cancel
Showing results for 
Search instead for 
Did you mean: 

optional elements with minOccurs 0 doesn't work?

bjornl
Champ in-the-making
Champ in-the-making
Hi,

I want to create optional elements in my web forms.
I've defined a form something like this:


<xs:complexType name="myType">
  <xs:sequence>
    <xs:element name="name" type="xs:normalizedString"/>
    <xs:element name="value" type="xs:normalizedString"/>
  </xs:sequence>
</xs:complexType>


<xs:element name="theName" type="myNS:myType minOccurs="0" maxOccurs="1"/>


Now in my form the "theName" element in the form is still required and I cannot save the form until I add it. Is this not the way of making optional elements? Did anyone come into this "problem"? Or anyone has a solution for it?

I am doing this on Alfresco 2.0.1 Enterprise

Regards,
Björn
3 REPLIES 3

arielb
Champ in-the-making
Champ in-the-making

<xs:element name="required_string" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
<xs:element name="optional_string" type="xs:normalizedString" minOccurs="0" maxOccurs="1"/>

arielb
Champ in-the-making
Champ in-the-making
i apologize - i didn't read your post closely enough.  i'd need to run some tests to figure out exactly what's going on - but intuitively, i think it has to do with where the xsi:nillable attribute is being inserted.  i'll run some tests tomorrow to see exactly what needs to be done here but in the meantime, my suggestion is to use attributes rather than sub elements if that works for you.  that should make the nillable propogate properly, so instead, try this:

<xs:complexType name="myType">
    <xs:attribute name="name" type="xs:normalizedString" use="required"/>
    <xs:attribute name="value" type="xs:normalizedString" use="required"/>
</xs:complexType>


<xs:element name="theName" type="myNS:myType minOccurs="0" maxOccurs="1"/>

please let me know if that works.

bjornl
Champ in-the-making
Champ in-the-making
Hi again.

I've tried using attributes as you suggest, to create complex types. However I receive a NullPointerException from Chiba when using attributes. Is this a well-known problem?

regards,
Björn