Problem with submission within xbl component

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

Problem with submission within xbl component

pumbosha
This post was updated on .
Hallo

I'm making my own component in xbl and I have to use submission within it. I have two parameters (resource, xpath) of submission which user can provide in form builder (like in autocomplete control):

<xbl:binding element="fr|myControl" id="fr-myControl" xxbl:mode="lhha binding value">
    <metadata xmlns="....">
    ....
    <templates>
        <instance label=""/>
        <view>
            <fr:myControl id="" appearance="minimal" xpath="" xmlns="" resource="" >
                <xf:label ref=""/>
                <xf:hint ref=""/>
                <xf:help ref=""/>
                <xf:alert ref=""/>
            </fr:myControl>       
        </view>
    </templates>

    <control-details>
        <xf:input ref="@resource">
            ....
        </xf:input>
        <xf:input ref="@xpath">
            ....
        </xf:input>
    </control-details>       
</metadata>
....

And then I want to call REST submission, with resource and result-xpath provided by the user in form builder (@resource and @xpath):

<xf:model>
    <xf:instance id="result"><value/></xf:instance>   
    <xf:instance id="sub"><value/></xf:instance> 
    <xf:instance id="resource"><value/></xf:instance> 
    <xf:instance id="xpath"><value/></xf:instance>     
    ....
    <xf:submission id="my-submission" instance="sub"
    mediatype="application/xml"
    method="get"
    resource="{instance('resource')}"
    replace="instance"
    serialization="none"/>                   
        <xf:action id="populate-data-binding">                         
            <xf:action context="instance('sub')"
            ev:event="xforms-submit-done"
            ev:observer="my-submission">                     
                <xf:action>                                                                     
                   
                    <xf:var as="xs:string" name="control-value" value="instance('xpath')"/>                           
                    <xf:setvalue ref="instance('result')" value="$control-value"/>

                </xf:action>               
            </xf:action>           
        </xf:action>
    </xf:model>

    ....

<xf:var name="resource-avt" xbl:attr="xbl:text=resource" xxbl:scope="outer"/>
<xf:var name="resource" xbl:attr="xbl:text=resource" >
    <xf:action ev:event="xforms-enabled xforms-value-changed">
        <xf:setvalue ref="instance('resource')" value="$resource"/>
    </xf:action>
</xf:var>
                       
<xf:var name="xpath-avt" xbl:attr="xbl:text=xpath" xxbl:scope="outer"/>
<xf:var name="xpath" xbl:attr="xbl:text=xpath" as="xs:string">
    <xf:action ev:event="xforms-enabled xforms-value-changed">
        <xf:setvalue ref="instance('xpath')" value="$xpath"/>
    </xf:action>
</xf:var>

My problem is in bold line above: In instance('xpath') I have value of parameter provided by user in form builder for example: '/pathToResult'. And I want to get part od xml-result from submission resource associated with '/pathToResult'. But unfortunately in result-instance (instance('result')) there is: '/pathToInstance' instead od result, for example for submision-resource xml:
<xml>
   <blabla>bla</blabla>
   <pathToResult>MY RESULT !!!</pathToResult>
</xml>
the expected value of result-instance is: 'MY RESULT !!!' instead of '/pathToResult'.
However if I modified line like:
<xf:var as="xs:string" name="control-value" value="/pathToResult"/>
it works good, but in this case the path would be hardcoded, but I want to give oportunity to form builder user to write it in control configuration.

How can I modify my code to reach expected effect ?

regards,
Tom
Reply | Threaded
Open this post in threaded view
|

Re: Problem with submission within xbl component

Alessandro  Vernet
Administrator
Hi Tom,

I think that saxon:evaluate() will solve your problem. If the following works:

<xf:var as="xs:string" name="control-value" value="/pathToResult"/>

But you don't want that XPath expression (/pathToResult) hardcoded there, and have it stored in instance('xpath'), then you should be able to write:

<xf:var as="xs:string" name="control-value" value="saxon:evaluate(instance('xpath'))"/>

For more on saxon:evaluate(), see:

http://saxonica.com/documentation9.1/extensions/functions/evaluate.html

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

Re: Problem with submission within xbl component

pumbosha
It works! Thank You a lot! You saved my time.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with submission within xbl component

Alessandro  Vernet
Administrator
Hi Tom,

Excellent, I'm glad it worked, and thanks for the update.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet