xs:choice

View: New views
3 Messages — Rating Filter:   Alert me  

xs:choice

by Deer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If I have schema xs:choice type. How should I design input and submit forms data.
Example schema
            <xs:element name="Contact">
                <xs:complexType>
                        <xs:choice>
                                <xs:element name="PostalAddress" type="PostalAddressType"/>
                                <xs:element name="ContactPerson" type="ContactPersonType"/>
                        </xs:choice>
                        <xs:attribute name="contactInformationID" type="xs:integer" use="required"/>
                </xs:complexType>
        </xs:element>

Re: xs:choice

by Tambet Matiisen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

This is what I did in my projects:

1. Add dummy attribute "choice" to Contact element in instance:
<Contact choice="1">
    <PostalAddress>...</PostalAddress>
    <ContactPerson>...</ContactPerson>
</Contact>

2. Add select1 control to form with appearance=full, so it will be
displayed as radio buttons:
<group ref="Contact">
    <label>Contact</label>
    <select1 ref="@choice" appearance="full">
        <item>
           <value>1</value>
           <label>Postal address</label>
        </item>
        <item>
           <value>2</value>
           <label>Contact person</label>
        </item>
    </select>
    ...controls for PostalAddress...
    ...controls for ContactPerson...
</group>

3. Make subelements relevant only when appropriate radio button is selected:
<bind nodeset="Contact">
    <bind nodeset="PostalAddress" relevant="../@choice = '1'"/>
    <bind nodeset="ContactPerson" relevant="../@choice = '2'"/>
</bind>

If you would prefer to not submit additional choice attribute, then you
need bit more work:

4. Add temporary instance with one boolean element "relevant":
<instance id="temp">
    <temp>
       <relevant>true</relevant>
    </temp>
</instance>

5. Set this element to false before submit and back to true after submit:
<submission ...>
    <setvalue events:event="xforms-submit"
ref="instance('temp')/relevant" value="false()"/>
    <setvalue events:event="xforms-submit-error"
ref="instance('temp')/relevant" value="true()"/>
    <setvalue events:event="xforms-submit-done"
ref="instance('temp')/relevant" value="true()"/>
</submission>

6. Bind "choice" attribute relevance to the element "relevant" in
temporary instance:
<bind nodeset="Contact">
    <bind nodeset="@choice"
relevant="boolean-from-string(instance('temp')/relevant)"/>
</bind>

I would be glad to hear about any alternatives.

  Tambet

Deer wrote:

> If I have schema xs:choice type. How should I design input and submit forms
> data.
> Example schema
>             <xs:element name="Contact">
> <xs:complexType>
> <xs:choice>
> <xs:element name="PostalAddress" type="PostalAddressType"/>
> <xs:element name="ContactPerson" type="ContactPersonType"/>
> </xs:choice>
> <xs:attribute name="contactInformationID" type="xs:integer"
> use="required"/>
> </xs:complexType>
> </xs:element>
>
>  


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Chiba-users mailing list
Chiba-users@...
https://lists.sourceforge.net/lists/listinfo/chiba-users

Re: xs:choice

by Deer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I try this example but it doesn't work. If it's possible to explain more or explain another example ka.
LightInTheBox - Buy quality products at wholesale price!