include model conditionally

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

include model conditionally

David Lacy

Hello,

 

I am attempting to include multiple models based on certain parameters, but for some reason the conditions are ignored and the models are included anyway. I am using the xforms:group method discussed here [1]. Attached is a working example of the issue. In the example “modal-a” should be included but “model-b” should not, yet both are displayed in the debugger. I swapped out the xforms:model content for some regular xhtml and the includes worked correctly, so I am lead to believe that it affects the xforms:model explicitly.

 

Thanks,

 

David Lacy

Falvey Library Technology Services

Villanova University

library.villanova.edu

 

[1] http://orbeon-forms-ops-users.24843.n4.nabble.com/Using-Xsl-copy-and-or-Xi-include-td278284.html

 

 



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws

include_model.ZIP (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: include model conditionally

Paolo Nacci
Orbeon will generate html for both groups, but one will be hidden. That's correct because group is tied to a variable that could change after model generation (you could place a control, bound to <load-b>, to change value from no to yes).

You can xinclude different xhtml through xpl (<p:choose> element).

page-flow.xml
<config xmlns="http://www.orbeon.com/oxf/controller">		   
	<page id="load" path-info="*" model="conditional-include.xpl"/>
</config>

conditional-include.xpl
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
    xmlns:oxf="http://www.orbeon.com/oxf/processors"
    xmlns:xforms="http://www.w3.org/2002/xforms">
	
    <!-- Get request parameter 'load-a' and 'load-b' (http://orbeon-server.../?load-a=yes&load-b=no) -->
    <p:processor name="oxf:request">
        <p:input name="config">
            <config>
                <include>/request/parameters</include>
            </config>
        </p:input>
        <p:output name="data" id="request"/>
    </p:processor>
	<p:processor name="oxf:identity">
		<p:input name="data"><xforms:group/></p:input>
		<p:output name="data" id="empty"/>
	</p:processor>
    <p:choose href="#request">
        <p:when test="/request/parameters/parameter[name = 'load-a']/value='yes' and /request/parameters/parameter[name = 'load-b']/value='yes'">
			<p:processor name="oxf:xinclude">
				<p:input name="config" href="view.xhtml"/>
				<p:input name="model-a-content" href="view-a.xhtml"/>
				<p:input name="model-b-content" href="view-b.xhtml"/>
				<p:output name="data" id="final-view"/>
			</p:processor>
        </p:when>
        <p:when test="/request/parameters/parameter[name = 'load-a']/value='yes' and /request/parameters/parameter[name = 'load-b']/value='no'">
			<p:processor name="oxf:xinclude">
				<p:input name="config" href="view.xhtml"/>
				<p:input name="model-a-content" href="view-a.xhtml"/>
				<p:input name="model-b-content" href="#empty"/>
				<p:output name="data" id="final-view"/>
			</p:processor>
        </p:when>
        <p:when test="/request/parameters/parameter[name = 'load-a']/value='no' and /request/parameters/parameter[name = 'load-b']/value='yes'">
			<p:processor name="oxf:xinclude">
				<p:input name="config" href="view.xhtml"/>
				<p:input name="model-a-content" href="#empty"/>
				<p:input name="model-b-content" href="view-b.xhtml"/>
				<p:output name="data" id="final-view"/>
			</p:processor>
        </p:when>
		<p:otherwise>
			<p:processor name="oxf:xinclude">
				<p:input name="config" href="view.xhtml"/>
				<p:input name="model-a-content" href="#empty"/>
				<p:input name="model-b-content" href="#empty"/>
				<p:output name="data" id="final-view"/>
			</p:processor>
		</p:otherwise>
	</p:choose>
	<p:processor name="oxf:pipeline">
        <p:input name="data" href="#final-view"/>
        <p:input name="config" href="/config/epilogue.xpl"/>
    </p:processor>
</p:config>

view.xhtml
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xforms="http://www.w3.org/2002/xforms"
            xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
            xmlns:xi="http://www.w3.org/2003/XInclude">
    <xhtml:head>
    </xhtml:head>
    
    <xhtml:body>
	 <xi:include href="input:model-a-content"/>
	 <xi:include href="input:model-b-content"/>
        <!-- Debugger -->
        <fr:xforms-inspector xmlns:fr="http://orbeon.org/oxf/xml/form-runner"/>        
    </xhtml:body>
</xhtml:html>

view-a.xhtml
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xforms="http://www.w3.org/2002/xforms">
<xforms:group appearance="xxforms:fieldset">
	<xforms:label>view-a</xforms:label>
	<h1>Text from dynamic inclusion of view-a.xhtml</h1>
</xforms:group>
</xhtml:html>

view-b.xhtml
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xforms="http://www.w3.org/2002/xforms">
<xforms:group appearance="xxforms:fieldset">
	<xforms:label>view-a</xforms:label>
	<h1>Text from dynamic inclusion of view-b.xhtml</h1>
</xforms:group>
</xhtml:html>

Another way, if your goal is to have a different instance content, is to load instance with an action bound to "xforms-ready" event:
...
       <xforms:model id="main-model">
            <xforms:instance id="load-model">
                <instance>
                    <load-a>yes</load-a>
                    <load-b>no</load-b>
                </instance>
            </xforms:instance>
	    <xforms:instance id="instance-a">
		<dummy/>
	    </xforms:instance>
	    <xforms:instance id="instance-b">
		<dummy/>
	    </xforms:instance>
	    <xforms:submission id="load-instance-a"  method="get" resource="instance-a-data.xml" instance='instance-a' replace='instance'/>
	    <xforms:submission id="load-instance-b"  method="get" resource="instance-b-data.xml" instance='instance-b' replace='instance'/>
	    <xforms:action ev:event="xforms-ready">
		<xforms:send if="instance('load-model')/load-a='yes'" submission="load-instance-a"/>
		<xforms:send if="instance('load-model')/load-b='yes'" submission="load-instance-b"/>
	    </xforms:action>        
	</xforms:model>
...
Reply | Threaded
Open this post in threaded view
|

Re: include model conditionally

Ethan Gruber
In reply to this post by David Lacy
Hi David,

I believe that XIncludes are added when your view.xhtml is built.  I don't think you can create a conditional in that scenario since model-a.xml and model-b.xml are included into your view before the XForms processor even begins working.  Can you use XBL components instead?

Ethan Gruber
American Numismatic Society

On Fri, Feb 24, 2012 at 1:27 PM, David Lacy <[hidden email]> wrote:

Hello,

 

I am attempting to include multiple models based on certain parameters, but for some reason the conditions are ignored and the models are included anyway. I am using the xforms:group method discussed here [1]. Attached is a working example of the issue. In the example “modal-a” should be included but “model-b” should not, yet both are displayed in the debugger. I swapped out the xforms:model content for some regular xhtml and the includes worked correctly, so I am lead to believe that it affects the xforms:model explicitly.

 

Thanks,

 

David Lacy

Falvey Library Technology Services

Villanova University

library.villanova.edu

 

[1] http://orbeon-forms-ops-users.24843.n4.nabble.com/Using-Xsl-copy-and-or-Xi-include-td278284.html

 

 



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Re: include model conditionally

David Lacy

Ethan,

 

You are right of course, thanks for making that clear. Unfortunately an XBL doesn’t fit the scope of what I’m looking to accomplish.

 

Thanks,

 

David Lacy

Falvey Library Technology Services

Villanova University

library.villanova.edu

610-519-7361

 

From: Ethan Gruber [mailto:[hidden email]]
Sent: Saturday, February 25, 2012 11:38 AM
To: [hidden email]
Subject: [ops-users] Re: include model conditionally

 

Hi David,


I believe that XIncludes are added when your view.xhtml is built.  I don't think you can create a conditional in that scenario since model-a.xml and model-b.xml are included into your view before the XForms processor even begins working.  Can you use XBL components instead?

 

Ethan Gruber

American Numismatic Society

 



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Re: include model conditionally

David Lacy
In reply to this post by Paolo Nacci
Paolo,

This worked perfectly. Thanks for the extremely detailed example.

David Lacy
Falvey Library Technology Services
Villanova University
library.villanova.edu
610-519-7361

> -----Original Message-----
> From: Paolo Nacci [mailto:[hidden email]]
> Sent: Saturday, February 25, 2012 11:37 AM
> To: [hidden email]
> Subject: [ops-users] Re: include model conditionally
>
> Orbeon will generate html for both groups, but one will be hidden. That's correct
> because group is tied to a variable that could change after model generation (you
> could place a control, bound to <load-b>, to change value from no to yes).
>
> You can xinclude different xhtml through xpl (
> http://wiki.orbeon.com/forms/doc/developer-guide/xml-pipeline-language-xpl#TOC-
> p:choose-element
> <p:choose> element ).
>
> *page-flow.xml*
>
>
> *conditional-include.xpl*
>
>
> *view.xhtml*
>
>
> *view-a.xhtml*
>
>
> *view-b.xhtml*
>
>
> Another way, if your goal is to have a different instance content, is to load
> instance with an action bound to "xforms-ready" event:
>
>
> --
> View this message in context: http://orbeon-forms-ops-
> users.24843.n4.nabble.com/include-model-conditionally-tp4418220p4420441.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws