Populate Model With XBL, Use the model in controls initial values

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

Populate Model With XBL, Use the model in controls initial values

Joel Oates
Hello,

I am currently trying to use XBL components to do a rest call and store the
data and insert that into the model of a form so controls can use the data
and save it. Now I have achieved making the rest call and populating an
instance with my data and inserting it into the form (Code below). But now I
am having an issue when I use the data I only cause use the calculated value
on a control to access the data rather than the initial value. Is there a
way I can make sure the XBL component is called so the initial value can see
the instance that I insert into the model?

<xbl:xbl>
    <xbl:binding id="im-populate-user-model"
element="im|populate-user-model" xxbl:mode="binding lhha">
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">Tutorial Check</display-name>
            <icon lang="en">
                <small-icon>/apps/fr/style/images/silk/html.png</small-icon>
                <large-icon>/apps/fr/style/images/silk/html.png</large-icon>
            </icon>
            <datatype>xf:string</datatype>
            <template>
                <im:populate-user-model id="" ref="" xmlns="">
                    <xf:label ref="" />
                    <xf:hint ref="" />
                    <xf:help ref="" />
                    <xf:alert ref="$fr-resources/detail/labels/alert" />
                </im:populate-user-model>
            </template>
        </metadata>
       
        <xbl:template>
            <xf:model id="local-model">
            <xf:instance id="prototypes">
            <user/>
            </xf:instance>
           
                 <xf:instance id="user-profile">
                    <UserProfile/>
                </xf:instance>
                <xf:submission id="get-current-user-profile" method="get"
replace="instance"
                    instance="user-profile"
                   
action="{concat(xxf:property('im.rest.uri.info'),'/user/profile')}">
                    <xf:header>
                        <xf:name>Accept</xf:name>
                        <xf:value>application/xml</xf:value>
                    </xf:header>
                    <xf:message ev:event="xforms-submit-error"
level="modal">
                        An error occurred
                        querying your user profile. Please contact your
system administrator.
                    </xf:message>
                </xf:submission>      
            </xf:model>
           
            <xf:group id="im-component-group" model="local-model">
                <xf:var name="binding"
value="xxf:binding('im-populate-user-model')" />
                <xf:var name="readonly" value="fr:is-readonly-mode()" />
               
                <xf:var name="builder" value="fr:is-design-time()" />

                <xf:action ev:event="xforms-enabled"
ev:target="im-component-group"
                    if="not($readonly) and not($builder)">
                    <xf:send submission="get-current-user-profile" />
                   
                    <xf:delete ref="xxf:instance('user')/*"/>
                   
                    <xf:insert context="xxf:instance('user')"
                    origin="instance('prototypes')/*" />

                </xf:action>
            </xf:group>
        </xbl:template>
    </xbl:binding>
</xbl:xbl>


Other ways to achieve this without using XBL components are to use the
action submission with data-sets, the data-set approach calls the
*fr-run-form-load-action-before-data* action, which I tried to use but I
could not get it to trigger in the XBL component. So my question here is,
can I populate a model and insert it into an instance for a control to use
it with xxf:default (initial value)?

Thanks,
Joel.



--
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: Populate Model With XBL, Use the model in controls initial values

Alessandro  Vernet
Administrator
Hi Joel,

I am not sure to follow; are you saying that `<xf:bind xxf:default="…">`
inside an XBL component isn't working for you? Would you be able to create
a minimal example that reproduces the problem, that we can run here, and
attach it a response so we can look into 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
Reply | Threaded
Open this post in threaded view
|

Re: Populate Model With XBL, Use the model in controls initial values

Joel Oates
Hi Alex,

Thanks for your reply, Sorry if I wasn't clear on my initial post. I have
made a little example of what I am trying to do.


I have created a sample of my issue, Here is my form that is trying to use
values of an instance that is populated by an XBL component as initial
values.


*The xForm Template*

<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/>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true"
xxf:analysis.calculate="true">

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

           
            <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="instance('test-instance')/PLANT[1]/COMMON"/>
                    <xf:bind id="control-2-bind" ref="control-2"
name="control-2" xxf:whitespace="trim"
                           
xxf:default="instance('test-instance')/PLANT[1]/PRICE"/>
                    <xf:bind id="control-3-bind" ref="control-3"
name="control-3" xxf:whitespace="trim"
                           
calculate="instance('test-instance')/PLANT[1]/COMMON"/>
                    <xf:bind id="control-4-bind" ref="control-4"
name="control-4" xxf:whitespace="trim"
                           
calculate="instance('test-instance')/PLANT[1]/PRICE"/>
                   
                </xf:bind>
            </xf:bind>

           
            <xf:instance xxf:readonly="true" id="fr-form-metadata"
xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>CPF</application-name>
                    <form-name>temp</form-name>
                    <title xml:lang="en"/>
                    <description xml:lang="en"/>
                    <version-comment>sdfsdf</version-comment>
                </metadata>
            </xf:instance>

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

           
            <xf:instance xxf:readonly="true" id="fr-form-resources"
xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <control-1>
                            <label>Plant Name (Initial Value)</label>
                            <hint/>
                           
                        </control-1>
                        <control-2>
                            <label>Plant Price (Initial Value)</label>
                            <hint/>
                        </control-2>
                        <control-3>
                            <label>Plant Name (Calculated Value)</label>
                            <hint/>
                        </control-3>
                        <control-4>
                            <label>Plant Praice (Calculated Value)</label>
                            <hint/>
                        </control-4>
                        <section-1>
                            <label>Test XBL Model</label>
                        </section-1>
                       
                    </resource>
                </resources>
            </xf:instance>

            <xf:instance id="test-instance">
                <data/>
            </xf:instance>
           
        </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">
                <im:test-xbl
xmlns:im="http://www.infomedix.com.au/cpf/forms"/>
                <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 x="7" y="1" w="6" h="1">
                            <xf:input id="control-2-control"
bind="control-2-bind">
                                <xf:label
ref="$form-resources/control-2/label"/>
                                <xf:hint
ref="$form-resources/control-2/hint"/>
                                <xf:alert
ref="$fr-resources/detail/labels/alert"/>
                       
                       
                            </xf:input>
                        </fr:c>
                        <fr:c x="1" y="2" w="6" h="1">
                            <xf:input id="control-3-control"
bind="control-3-bind">
                                <xf:label
ref="$form-resources/control-3/label"/>
                                <xf:hint
ref="$form-resources/control-3/hint"/>
                                <xf:alert
ref="$fr-resources/detail/labels/alert"/>
                       
                       
                            </xf:input>
                        </fr:c>
                        <fr:c x="7" y="2" w="6">
                            <xf:input id="control-4-control"
bind="control-4-bind">
                                <xf:label
ref="$form-resources/control-4/label"/>
                                <xf:hint
ref="$form-resources/control-4/hint"/>
                                <xf:alert
ref="$fr-resources/detail/labels/alert"/>
                       
                       
                            </xf:input>
                        </fr:c>
                    </fr:grid>
                </fr:section>
                <fr:xforms-inspector/>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

Here is the *im:test-xbl * XBL Component

<?xml version="1.0" encoding="UTF-8"?>

<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: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:exf="http://www.exforms.org/exf/1-0"
    xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
    xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
    xmlns:saxon="http://saxon.sf.net/"
    xmlns:im="http://www.infomedix.com.au/cpf/forms"
    xmlns:xbl="http://www.w3.org/ns/xbl"
    xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

    <xbl:binding
        id="im-test-xbl"
        element="im|test-xbl"
        xxbl:mode="lhha binding">
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">Populate Sample Models</display-name>
            <icon lang="en">
            </icon>
            <template>
                <im:test-xbl
                    id=""
                    ref=""
                    xmlns="">
                    <xf:label ref="" />
                    <xf:hint ref="" />
                    <xf:help ref="" />
                    <xf:alert ref="$fr-resources/detail/labels/alert" />
                </im:test-xbl>
            </template>
        </metadata>
        <xbl:template>
           
            <xf:model id="local-model">
                <xf:instance id="rest-info">
                    <details>
                    </details>
                </xf:instance>

                <xf:submission id="get-details-info" method="get"
replace="instance"
                    instance="rest-info"
                   
action="https://www.w3schools.com/xml/plant_catalog.xml">

                    <xf:message
                        ev:event="xforms-submit-error"
                        level="modal">
                        An error occurred
                        querying the information. Please contact your system
administrator.
                    </xf:message>
                </xf:submission>

            </xf:model>

            <xf:group
                id="im-component-group"
                model="local-model">
               
                <xf:var name="readonly" value="fr:is-readonly-mode()" />
               
                <xf:var name="builder" value="fr:is-design-time()" />

                <xf:action
                    ev:event="xforms-enabled"
                    ev:target="im-component-group"
                    if="not($readonly) and not($builder)">
                    <xf:send submission="get-patient-info"/>
                   
                    <xf:send submission="get-details-info"/>
                   
                    <xf:insert context="xxf:instance('test-instance')"
                    origin="instance('rest-info')/*" />
                </xf:action>
            </xf:group>
        </xbl:template>
    </xbl:binding>
</xbl:xbl>

What I am trying to achieve is, To have the XBL component populate a model
for the template via a rest service, then we can use that model in the
template and for the template to keep those initial values once it has been
saved as a form.

Our current issue is that the initial values (xxf:default) is not working
when you try and populate an control. I have tried to use calculate which
works in using the instance model, but when we save the form and try and
view it again, it will not used the saved initial values, it does the
calculation again.

Thanks Again,
Joel.





--
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: Populate Model With XBL, Use the model in controls initial values

Alessandro  Vernet
Administrator
Hi Joel,

I see that in your form, you have 2 occurrences of `xxf:default`. Let's take
the first one:

    <xf:bind id="control-1-bind" name="control-1"
             ref="control-1" xxf:whitespace="trim"
             xxf:default="instance('test-instance')/PLANT[1]/COMMON"/>

It's referring to `test-instance`, which here is empty. I imagine that in
the real situation that instance would be initialized somehow? And
`control-1` isn't an XBL control, but an `xf:input`, and I don't see any use
of `xxf:default` inside the XBL component. What am I missing?

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

Re: Populate Model With XBL, Use the model in controls initial values

Joel Oates
Hi Alex,

The 'test-instance' that this control is referring to will be populated with
the XBL component im:text-xbl with:

<xf:insert context="xxf:instance('test-instance')"
                    origin="instance('rest-info')/*" />

This XBL inserts a populated instance to the test-instance, and then I want
to use that information to populate the control. Is this possible to do with
XBL components? Is it possiable to call an event on the XBL  components
before data load time?

Cheers,
Joel.


--
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: Populate Model With XBL, Use the model in controls initial values

Alessandro  Vernet
Administrator
Hi Joel,

So you're saying that the XBL control doesn't have a "UI", but is just used
to populate an instance. Instead of creating an XBL control and adding it to
the form, I'd recommend you put that model-specific code in a custom model
logic (see link below). You'll let me know if this works for you.

https://doc.orbeon.com/form-runner/advanced/custom

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

Re: Populate Model With XBL, Use the model in controls initial values

Alessandro  Vernet
Administrator
Hi Joel, did you get a chance to try using a custom model, instead of an XBL
component, as suggested in my previous message? If so, did it 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
Reply | Threaded
Open this post in threaded view
|

Re: Populate Model With XBL, Use the model in controls initial values

bwallis42
Hi Alex,
  Joel is in China for the next couple of weeks. He found an alternative to
this before leaving but we are still interested in chasing up this problem.
He will be looking into this once he is back from OS.

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

Re: Populate Model With XBL, Use the model in controls initial values

Alessandro  Vernet
Administrator
Hi Brian,

Got it, thank you for the update, and so I'll just let you or Joel follow-up
on this if the workaround isn't working, or you prefer to handle this in
some other way.

‑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