rest calls, datasets and initial values

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

rest calls, datasets and initial values

bwallis42
This post was updated on .
I have defined an HTTP service named jsontest that calls a rest service
(http://date.jsontest.com/). This works when I click test and returns a json
object with the current date and time in it.

I then defined an action also named jsontest that is set as run on creation
only, when the form loads and before the data's initial values are
calculated.

Next I set an initial value formula in a text field with
"concat(fr:dataset('jsontest')/date,':',fr:dataset('jsontest')/time)" in it.

When I create a new instance of this form I don't get a value in the text
field as I expected. If I change the action to run always then I get a
value.

Should this work with run on creation only, I think it should. Have I
misunderstood how this works?

The form source is

<xh:html 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:map="http://www.w3.org/2005/xpath-functions/map"
         xmlns:array="http://www.w3.org/2005/xpath-functions/array"
         xmlns:exf="http://www.exforms.org/exf/1-0"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:sql="http://orbeon.org/oxf/xml/sql"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
    <xh:head>
        <xh:title>a test form</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true" xxf:analysis.calculate="true">

            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
                <form>
                    <section-1>
                        <control-1/>
                    </section-1>
                </form>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                    <xf:bind id="control-1-bind" name="control-1" ref="control-1" xxf:whitespace="trim"
                             xxf:default="concat(fr:dataset('jsontest')/date,':',fr:dataset('jsontest')/time)"/>
                </xf:bind>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>CPF</application-name>
                    <form-name>bwtest2</form-name>
                    <title xml:lang="en">a test form</title>
                    <description xml:lang="en"/>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments/>
            </xf:instance>

            <!-- All form resources -->
            <xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <section-1>
                            <label>Untitled Section</label>
                        </section-1>
                        <control-1>
                            <label/>
                            <hint/>
                            
                        </control-1>
                    </resource>
                </resources>
            </xf:instance>

            <xf:instance id="jsontest-instance" class="fr-service" xxf:exclude-result-prefixes="#all">
                        <body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                      xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilderXPathApi">&lt;params/&gt;</body>
                    </xf:instance>
            <xf:submission id="jsontest-submission" class="fr-service"
                           resource="http://date.jsontest.com/"
                           method="get"
                           serialization="none"
                           mediatype="none"/>
            <xf:action id="jsontest-binding">
                <xf:action event="fr-run-form-load-action-before-data" ev:observer="fr-form-model"
                           if="$fr-mode='new'">
                    <xf:send submission="jsontest-submission"/>
                </xf:action>
                <xf:action event="xforms-submit" ev:observer="jsontest-submission">
                    <xf:var name="request-instance-name" value="'jsontest-instance'"/>
                    <xf:action/>
                </xf:action>
                <xf:action event="xforms-submit-done" ev:observer="jsontest-submission">
                    <xf:action class="fr-save-to-dataset-action">
                        <xf:var name="dataset-name">jsontest</xf:var>
                    </xf:action>
                </xf:action>
            </xf:action>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors">
                <fr:section id="section-1-section" bind="section-1-bind">
                    <xf:label ref="$form-resources/section-1/label"/>
                    <fr:grid id="grid-1-grid">
                        <fr:c y="1" x="1" w="6">
                                <xf:input id="control-1-control" bind="control-1-bind">
                                    <xf:label ref="$form-resources/control-1/label"/>
                                    <xf:hint ref="$form-resources/control-1/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    
                                </xf:input>
                            </fr:c>
                        <fr:c y="1" x="7" w="6"/>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: rest calls, datasets and initial values

Erik Bruchez
Administrator
Brian,

Based on your description, it should work. But the form source is missing.
Can you share it again?

-Erik

--
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].
Reply | Threaded
Open this post in threaded view
|

Re: rest calls, datasets and initial values

bwallis42
Thanks Erik,
  I've edited the post and added the source back in again. I'm having a lot
of trouble with the raw tags in posts, they seem to disappear when I post
the form if I have used the Preview Message button despite looking fine in
the preview.
brian...


--
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].