Accessing parameter with dynamic value in xbl component

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing parameter with dynamic value in xbl component

mabu
Hi,

I want to pass a parameter with a dynamic value to my xbl component. I tried it as described in http://wiki.orbeon.com/forms/doc/developer-guide/xbl-components-guide#TOC-Parameters-.
But I can't figure out how to access the parameter in the xbl component?

If I use a parameter with a static value, following code works to access the parameter:
<xf:var name="param1" xbl:attr="xbl:text=param1" />
Reply | Threaded
Open this post in threaded view
|

Re: Accessing parameter with dynamic value in xbl component

Alessandro  Vernet
Administrator
Hi Martin,

We've built some utility code to deal with that sort of parameters. You can see how it is called here, e.g. in <xsl:copy-of select="xxbl:parameter(., 'mindate')"/>:

https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/xbl/orbeon/date/date.xbl

But this might be more complicated than what you need. Could you give us an example of what using your XBL component would look like?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Accessing parameter with dynamic value in xbl component

mabu
Hi Alex,

In my XBL component I want to display different input fields according to a parameter.
If I use a parameter with a static value my component looks as follows:
<xbl:binding id="my-testcomponent" element="my|testcomponent>
    <xbl:template>
        ...
        <xf:var name="param1" xbl:attr="xbl:text=param1" />
        <xf:group ref="if($param1 = 'value1') then $form-instance else () appearance="xxf:internal">
            <!-- some input fields -->
        <xf:group>
        <xf:group ref="if($param1 = 'value2') then $form-instance else () appearance="xxf:internal">
            <!-- other input fields -->
        </xf:group>
        ....
    </xbl:template>
</xbl:binding>

<!-- Usage of component -->
<my:testcomponent param1="value1"/>

If I want to use a dynamic value for the parameter, according to the documentation I pass it as follows:
<my:testcomponent>
    <my:param1 = "./defaultvalue"/>
</my:testcomponent>
My question now is how to access this parameter in the XBL component?
Reply | Threaded
Open this post in threaded view
|

Re: Accessing parameter with dynamic value in xbl component

Alessandro  Vernet
Administrator
Hi Martin,

Try this:

1. Use XSLT in your XBL: <xbl:template xxbl:transform="oxf:unsafe-xslt">. (For the full code, see the example linked below.)
2. In the XSLT, include xbl.xsl: <xsl:import href="oxf:/oxf/xslt/utils/xbl.xsl"/>.
3. Also add <xsl:copy-of select="xxbl:parameter(., 'param1')"/>
4. To reference the value of param1, just use $param1.
5. (If you need to have JavaScript code called when the value changes, you can also define your own function which will be automatically called when that happens.).

And you can see an example where this is done (except for number 4 above) in:

https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/xbl/orbeon/date/date.xbl

I hope this helps,

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Accessing parameter with dynamic value in xbl component

mabu
Thanks Alex, it helped me a lot. Now it works fine!