This post was updated on .
Hi Alex,
I'am trying my own custom component with a companion class. The goal is to get a component which be able to validate a dni document. As a first step I need to get the value that users insert in the component, I thought the right way to get it is using the xformsUpdateValue method of the companion class. I thought that this method should be called automatically everytime that users type a new value in the field meanwhile they are interacting with the form in form runner, but the method is not called. What am I missing? should I add something in the xbl file in order to get this behavior?. Or maybe I am missunderstanding something about how the companion class works?. Please see below the xbl and js files: <xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:sede="http://www.sede.com/xbl" xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"> <xbl:script src="/xbl/sede/dni/dni.js"/> <xbl:binding element="sede|dni" id="sede-dni" xxbl:mode="lhha binding value external-value focus "> <metadata xmlns="http://orbeon.org/oxf/xml/form-builder"> <display-name lang="en">Dni</display-name> <display-name lang="es">Dni</display-name> </metadata> <xbl:template> <xf:model> <xf:instance><value/></xf:instance> </xf:model> <xf:input ref="instance()"> </xf:input> </xbl:template> </xbl:binding> </xbl:xbl> and the companion class: (function() { var $ = ORBEON.jQuery; ORBEON.xforms.XBL.declareCompanion('sede|dni', { init: function() { }, destroy: function() { }, xformsFocus: function() { }, xformsUpdateReadonly: function(readonly) { }, xformsUpdateValue: function(newValue) { window.alert("update value"); }, xformsGetValue: function() { } }); })(); Mention that other methods of the companion class are called, as for instance the init method if I set the javascript-lifecycle mode. -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to orbeon+unsubscribe@googlegroups.com. To post to this group, send email to orbeon@googlegroups.com. |
Administrator
|
Hi Vincente,
For `xformsUpdateValue` to be called you need the `javascript-lifecycle` mode to be enabled, which isn't the case in your XBL. You'll let me know if things work out after you add `javascript-lifecycle` to your `xxbl:mode="…"`. https://doc.orbeon.com/xforms/xbl/javascript.html#the-xformsupdatevalue-method Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex, I tried adding `javascript-lifecycle` and the result is the same,
`xformsUpdateValue` is not called, the method that is called (you don´t need 'javascript-lifecycle' only 'external-value') is 'xformsGetValue' , this method is called everytime the user change the value of the field. So maybe I had a wrong concept aboout these methods. I think that the method that is called when user change the value is 'xformsGetValue' and 'xformsUpdateValue' must be called from javascript in order to update a new value in the field. Does it make sense? On other hand, I would like also to know how call my own javascript function from the inside of the XBL component. I think It should be done adding an event on the xbl file, but i get errors. I tried two ways as you can see below, but with both i get errors: <xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:sede="http://www.sede.com/xbl" xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"> <xbl:script src="/xbl/sede/dni/dni.js"/> <xbl:binding element="sede|dni" id="sede-dni" xxbl:mode="lhha binding value external-value"> <metadata xmlns="http://orbeon.org/oxf/xml/form-builder"> <display-name lang="en">Dni</display-name> <display-name lang="es">Dni</display-name> </metadata> <xbl:template> <xf:model> <xf:instance><value/></xf:instance> </xf:model> <xf:input class="xbl-dni-input" ref="xxf:binding('sede-dni')"/> </xbl:template> </xbl:binding> </xbl:xbl> -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. |
Administrator
|
Hi Vincente,
Before digging into the details of those methods, could you tell us more about what your components does? If it isn't confidential information, can you share a screenshot or mockup of what the UI of the component should look like? (I'm asking because if, for instance, the value is managed by an `xf:input` inside the control, then you don't even want to use `external-value`, and don't need to worry about those methods.) Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex, actually I have two proposses:
1)Learning as much as possible about how custom components work. That's why I would like to go into these methods, then I could have an example for the future neededs. 2)In this specific case I want to do a custom component which would looks as a regular input field. The field is to hold a DNI value (it is a spanish document which consist in a letter and numbers). The validity of the entry can be done with a little bit of bussiness logic using javascript (I think xpath is not enought). Now I do it using two inputs (one for the DNI value and the other is hidden and I use it to hold a result), users insert the value in the DNI input then i call external javascript functions then javascript functions write a result in the hidden input (the result is different depending on if the value is valid or if it is invalid depending on if the error is in the number, letter, value lenght, etc..), then I set the validations formulas in the DNI input depending of the result of the hidden field. That I pretend with this custom component is to do the same in a more simple way and using only a single control. That's why I wanted to use the mentioned method to run a javascript function when users insert a value in the field, but I am not sure if it is the right way to do it. -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. |
Administrator
|
Hi Vincente,
1. Got it. For this, I'd recommend you scrupulously ;) go through the XBL documentation, then through the source of the built-in XBL components, and ask any question that comes up. (A question is typically a sign that we need to improve the documentation, and sometimes even fix something!) 2. I would really discourage you from doing the validation in JavaScript, because it means someone can go around it should they want to, and send data that isn't valid. You might have a case where nothing terrible will happen if have invalid data, but this is generally not a good practice. What does the validation code look like? If you can, doing it in XPath will make everything simpler. If not, you could write it in Java, and call the Java code from XPath. Would one of those options work for you? Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex, thanks for your reply. I discard to do it with xpath because besides
of a little of bussiness logic you have to keep some tables in memory, because first you have to calculate a value, and depending of this value you have to search on the tables for the corresponding letter. I know that it could be possible keep these tables in hidding fields, but i don´t find it is a good solution to do it in many forms. I agree with that you say about javascript, well you always could ofuscate the code, of course it wouldn´t be totally safe, but I think in this particular case there would be no problem, but Indeed it is not a good practice in general. That you say about call java code from xpath sounds interesting. Do you mean usingt saxon?. It would be possible to do it calling the java code from inside of my custom component (maybe using some xbl handler)? The question is that we prefer don´t touch the code that is created for orbeon builder, if it is not totally necesary. Could you go a little more into this?. I have looked in the official documentation but I did not find anything about calling java code from xpath. -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. |
Administrator
|
Hi Vincente,
Yes, Orbeon Forms uses Saxon, which allows you to call static methods of your own Java classes (see below). So you would need to add a jar with your code to Orbeon Forms `WEB-INF/lib`, in Form Builder edit the source to declare a namespace pointing to your class (see Saxon doc linked below), and then call that code from XPath, e.g. anywhere where you can write XPath in Form Builder. http://www.saxonica.com/documentation9.1/extensibility/functions/staticmethods.html Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
This post was updated on .
Hi Alex, maybe because I am not very use to xslt and xpath languages I does
not find very clear how to call a java static method reading this documentation. That would be really usefull for me is to be able to call a java method writting a formula in xpath in the validations tab or/and in the formulas tab of form builder. I understand that when you say "anywhere where you can write XPath in Form Builder" it could be possible. It is? If you could show me a very simple example. For example, just for a demostration, sax documentation tells that you can call a static method using xslt in this way: <xsl:value-of select="math:sqrt($arg)" xmlns:math="java:java.lang.Math"/> But it is not xpath and I can not write it in the formulas tab of form builder. Then my question is how would you write it in xpath here: for example to get that the calculated value of this field be the squart of the value of other field....¡Please notice that it is a simple example to see how you would call the java static method using an xpath expression!( I have choosed the squart function only because it is a java starndard function then I don´t need to add my own java code for the moment) -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to orbeon+unsubscribe@googlegroups.com. To post to this group, send email to orbeon@googlegroups.com. |
Administrator
|
Hi Vincente,
Sure, for instance: 1. In Form Builder, edit the source of the form (Advanced / Edit Source). On the root element, add: `xmlns:math="java:java.lang.Math"`. <http://discuss.orbeon.com/file/t119778/added-ns.png> 2. Set a field calculated value as `math:sqrt(49)`. <http://discuss.orbeon.com/file/t119778/calc.png> 3. Run the form, and you'll see that the field value is 7. Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex, thanks you very much. It is really simple but useful. I was able to
add my own .jar and call the methods using xpath. I find this orbeon feature very useful. -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. |
Administrator
|
Excellent Vincente, I'm glad calling Java this way works for you. It's nice
to have "a box" (here in the case of XPath), but it's also useful at times to be able to get out of it. Alex ----- -- Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet -- Sent from: http://discuss.orbeon.com/ -- You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Free forum by Nabble | Edit this page |