Вопрос

I'm newbie in Orbeon xforms, so I ask my questions here. I have REST webservice with some address (method GET) and I want to call him and the result should be provide to metadata of my form:

<!-- Main instance -->
<xforms:instance id="fr-form-instance">
    <form>
        <section-meta>
            <resultOfMyRestWebservice/>

I've tried to follow this tutorial http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data (pull solution) but I don't know how I can put the result of rest in the marker: resultOfMyRestWebservice, and where I have to put the submission code:

<xforms:submission
    id="load-data-submission"
    method="get" serialization="none"
    resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
    replace="?" instance="?"/>

regards

Это было полезно?

Решение

If I were you I would use a temporary run-time instance to hold the results of your REST call and then use setvalue to populate your persisting instance.

The following example works if you define the structure of your meta-data in your model, so you can use setvalue to populate. Otherwise you can use insert.

Ie. In your xforms:model define:

<!-- Run-time instance to hold Service response -->
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
    <response/>
</xforms:instance>

Define your submission to replace this response instance:

<xforms:submission id="load-data-submission" method="get"
    serialization="none" mediatype="application/xml"
    resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
    replace="instance" instance="fr-service-response-instance"/>

And then create an action to call the submission and populate your instance:

<!-- Populate Data
     uses Load Data Submission
     runs on form load -->
<xforms:action id="populate-data-binding">
    <xforms:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
         <xforms:send submission="load-data-submission"/>
    </xforms:action>
    <!-- Populate resultOfMyRestWebservice control with pathToResults value
         following successful submission -->
    <xforms:action ev:event="xforms-submit-done" ev:observer="load-data-submission"
                context="instance('fr-service-response-instance')">
         <xforms:action>
               <xf:var name="control-name" value="'resultOfMyRestWebservice'" as="xs:string"/>
               <xf:var name="control-value" value="/pathToResults" as="xs:string"/>
               <xforms:setvalue ref="instance('fr-form-instance')/*/*[name() = $control-name]"
                        value="$control-value"/>
         </xforms:action>
    </xforms:action>
</xforms:action>

Note pathToResults is the xpath to the value you want from the results.

Другие советы

I do everything like in mentioned tutorial: http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data I mean:

....
 <xf:model id="fr-form-model" xxf:expose-xpath-types="true">


        <!-- User in which user data is collected -->
        <xf:instance id="user-data">
            <registration>
                <first-name/>
                <last-name/>
            </registration>
        </xf:instance>

        <!-- Load initial data from a service -->
        <xf:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
        <xf:submission id="load-data-submission" method="get" serialization="none"
                       resource="http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml"
                       replace="instance"
                       instance="user-data"/>

        <!-- Main instance -->
        <xf:instance id="fr-form-instance">
            <form>
                <name/>
....
....
 <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                 xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline">
....
    <xforms:action ev:event="xforms-enabled">
    <xforms:setvalue ref="xxf:instance('fr-form-instance')/name"
        value="xxf:instance('user-data')/first-name"/>              
    </xforms:action>
</fr:body>
....

I want to get xml from link (http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml), put in to the 'user-data' instance and then get the first-name and put to the 'name' marker in the 'fr-form-instance'. Unfortunately it does not working, I mean setvalue not working, because when I change 'user-instance' like that:

<xf:instance id="user-data">
    <registration>
        <first-name>SomeName</first-name>
        <last-name/>
    </registration>
</xf:instance>

it working, and the final xml look like:

....
<name>SomeName</name>
....

I really haven't idea why it doesn't working.

regards

///

Now I see that my problem may be reduced to:

It works:

<xforms:instance id="user-data" src="http://example.org/service/load-initial-form-data-pull-instance"/>

And it does not work:

<xforms:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xforms:submission id="load-data-submission"
               method="get" serialization="none"
               resource="http://example.org/service/load-initial-form-data-pull-instance"
               replace="instance" instance="user-data"/>

I have to use second way, because I have to pass some parameter to resource (resource="http.../{xxforms:get-request-parameter('myParam')}")

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top