dear ops gurus,
i'm struggling with the following and would greatly appreciate any help: Suppose i have an XML-Schema that defines an element as optional: schema.xsd: ... <element name="age" type="positiveInteger" minOccurs="0" /> ... This schema is used as the schema for an XForms model and a an <input> is bound to the <age> element as usual: view.xhtml: ... <model schema="schema.xsd"> ... <input ref="age"/> ... I want to achieve that the submitted instance document 1. either contains no <age> element (if the user didn't input an age) or 2. contains a non-empty <age> element (containing the positive integer supplier by the user). My dilemma is this: 1. if i supply an XForm instance document with an empty <age> element view.xhtml: ... <model schema="schema.xsd"> <instance> ... <age/> ... </instance> </model> then the user is shown a textfield to input the age. But if he does not input any age, then the submitted instance document contains an empty <age> element - which is not what i want. 2. if, on the other hand, i supply an XForm instance document without an <age> element then the user is not shown a textfield to input the age (because the ref points to an empty nodeset; and the submitted instance document never contains the <age> element). I suppose i could fiddle around with <insert> and <delete> to add/remove <age> elements when the user is or is not about to enter his age. But i hoped that this would not be necessary... any ideas??. thanks a lot in advance!, gerald -- dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
My suggestion would be to use some xslt to get the document into the
format you want -- ie wherever you submit it to would do this as the first step. (Or possibly XUpdate). -----Original Message----- From: Gerald Loeffler [mailto:[hidden email]] Sent: 07 December 2005 17:27 To: [hidden email] Subject: [ops-users] XForms: absent vs. empty elements dear ops gurus, i'm struggling with the following and would greatly appreciate any help: Suppose i have an XML-Schema that defines an element as optional: schema.xsd: ... <element name="age" type="positiveInteger" minOccurs="0" /> ... This schema is used as the schema for an XForms model and a an <input> is bound to the <age> element as usual: view.xhtml: ... <model schema="schema.xsd"> ... <input ref="age"/> ... I want to achieve that the submitted instance document 1. either contains no <age> element (if the user didn't input an age) or 2. contains a non-empty <age> element (containing the positive integer supplier by the user). My dilemma is this: 1. if i supply an XForm instance document with an empty <age> element view.xhtml: ... <model schema="schema.xsd"> <instance> ... <age/> ... </instance> </model> then the user is shown a textfield to input the age. But if he does not input any age, then the submitted instance document contains an empty <age> element - which is not what i want. 2. if, on the other hand, i supply an XForm instance document without an <age> element then the user is not shown a textfield to input the age (because the ref points to an empty nodeset; and the submitted instance document never contains the <age> element). I suppose i could fiddle around with <insert> and <delete> to add/remove <age> elements when the user is or is not about to enter his age. But i hoped that this would not be necessary... any ideas??. thanks a lot in advance!, gerald -- dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
thanks stephen,
but the problem than is that i can't use the given schema (schema.xsd below) as the schema for the XForm model, because an existent but empty <age> element would be invalid against that schema...(or is it not?) cheers, gerald Stephen Bayliss wrote: > My suggestion would be to use some xslt to get the document into the > format you want -- ie wherever you submit it to would do this as the > first step. (Or possibly XUpdate). > > -----Original Message----- > From: Gerald Loeffler [mailto:[hidden email]] > Sent: 07 December 2005 17:27 > To: [hidden email] > Subject: [ops-users] XForms: absent vs. empty elements > > dear ops gurus, > > i'm struggling with the following and would greatly appreciate any help: > > Suppose i have an XML-Schema that defines an element as optional: > > schema.xsd: > ... > <element name="age" type="positiveInteger" minOccurs="0" /> > ... > > This schema is used as the schema for an XForms model and a an <input> > is bound to the <age> element as usual: > > view.xhtml: > ... > <model schema="schema.xsd"> > ... > <input ref="age"/> > ... > > I want to achieve that the submitted instance document > 1. either contains no <age> element (if the user didn't input an age) > or > 2. contains a non-empty <age> element (containing the positive > integer supplier by the user). > > My dilemma is this: > 1. if i supply an XForm instance document with an empty <age> element > > view.xhtml: > ... > <model schema="schema.xsd"> > <instance> > ... > <age/> > ... > </instance> > </model> > > > then the user is shown a textfield to input the age. But if he does not > input any age, then the submitted instance document contains an empty > <age> element - which is not what i want. > 2. if, on the other hand, i supply an XForm instance document without > > an <age> element then the user is not shown a textfield to input the age > > (because the ref points to an empty nodeset; and the submitted instance > document never contains the <age> element). > > I suppose i could fiddle around with <insert> and <delete> to add/remove > > <age> elements when the user is or is not about to enter his age. But i > hoped that this would not be necessary... > > any ideas??. > thanks a lot in advance!, > gerald > > > ------------------------------------------------------------------------ > > > -- > 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 > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Gerald Loeffler wrote:
> thanks stephen, > > but the problem than is that i can't use the given schema (schema.xsd > below) as the schema for the XForm model, because an existent but empty > <age> element would be invalid against that schema...(or is it not?) Yes, it would be invalid if empty, because an empty string is not a positiveInteger. This is a tough case: you cannot easily add or remove the <age> element in XForms right now (XForms 1.0) anyway, because you need a prototype element to copy with xforms:insert, and if you have no age element in the first place, you don't have a prototype. If you could accept a trailing <age> element as prototype, when you could use xforms:insert to add the age when the user presses a button. Alternatively, you could do this with a submission that updates the instance, i.e. when you user presses a button the instance is submitted and some server-side code adds the <age> element. This poses the problem that the instance won't submit if it is not valid... There is a proposal now in XForms 1.1 to have an xforms:duplicate or an upgraded xforms:insert action that will allow inserting elements from other sources (not just by duplicating a prototype element which is a sibling of the new element). This would allow implementing your case, provided the user must click on a button or something to trigger the insertion of the <age> element. -Erik -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
hi Erik,
i had forgotten that i need a prototype to use <insert> - this unfortunately means that there is no way to dynamically construct the instance document to contain exactly the elements i need. one more thought: can't i use "relevant" to suppress the submission of elements which are empty just before submission? So the initial instance document would contain an empty <age> element, and if the user does not enter an age, the serialisation of <age> is suppressed by setting relevant to false just before the instance is submitted. I don't know if elements with relevant=false are considered for validation against the schema, though... thanks once more!, gerald Erik Bruchez wrote: > Gerald Loeffler wrote: > >> thanks stephen, >> >> but the problem than is that i can't use the given schema (schema.xsd >> below) as the schema for the XForm model, because an existent but >> empty <age> element would be invalid against that schema...(or is it >> not?) > > > Yes, it would be invalid if empty, because an empty string is not a > positiveInteger. > > This is a tough case: you cannot easily add or remove the <age> element > in XForms right now (XForms 1.0) anyway, because you need a prototype > element to copy with xforms:insert, and if you have no age element in > the first place, you don't have a prototype. If you could accept a > trailing <age> element as prototype, when you could use xforms:insert to > add the age when the user presses a button. Alternatively, you could do > this with a submission that updates the instance, i.e. when you user > presses a button the instance is submitted and some server-side code > adds the <age> element. This poses the problem that the instance won't > submit if it is not valid... > > There is a proposal now in XForms 1.1 to have an xforms:duplicate or an > upgraded xforms:insert action that will allow inserting elements from > other sources (not just by duplicating a prototype element which is a > sibling of the new element). This would allow implementing your case, > provided the user must click on a button or something to trigger the > insertion of the <age> element. > > -Erik > > > > ------------------------------------------------------------------------ > > > -- > 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 > ObjectWeb mailing lists service home page: http://www.objectweb.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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
In reply to this post by Gerald Loeffler
Can you not validate it against the schema at a later stage; ie after
you've removed the empty <age> node? -----Original Message----- From: Gerald Loeffler [mailto:[hidden email]] Sent: 07 December 2005 18:45 To: [hidden email] Subject: Re: [ops-users] XForms: absent vs. empty elements thanks stephen, but the problem than is that i can't use the given schema (schema.xsd below) as the schema for the XForm model, because an existent but empty <age> element would be invalid against that schema...(or is it not?) cheers, gerald Stephen Bayliss wrote: > My suggestion would be to use some xslt to get the document into the > format you want -- ie wherever you submit it to would do this as the > first step. (Or possibly XUpdate). > > -----Original Message----- > From: Gerald Loeffler [mailto:[hidden email]] > Sent: 07 December 2005 17:27 > To: [hidden email] > Subject: [ops-users] XForms: absent vs. empty elements > > dear ops gurus, > > i'm struggling with the following and would greatly appreciate any > > Suppose i have an XML-Schema that defines an element as optional: > > schema.xsd: > ... > <element name="age" type="positiveInteger" minOccurs="0" /> > ... > > This schema is used as the schema for an XForms model and a an <input> > is bound to the <age> element as usual: > > view.xhtml: > ... > <model schema="schema.xsd"> > ... > <input ref="age"/> > ... > > I want to achieve that the submitted instance document > 1. either contains no <age> element (if the user didn't input an > or > 2. contains a non-empty <age> element (containing the positive > integer supplier by the user). > > My dilemma is this: > 1. if i supply an XForm instance document with an empty <age> > > view.xhtml: > ... > <model schema="schema.xsd"> > <instance> > ... > <age/> > ... > </instance> > </model> > > > then the user is shown a textfield to input the age. But if he does > input any age, then the submitted instance document contains an empty > <age> element - which is not what i want. > 2. if, on the other hand, i supply an XForm instance document > > an <age> element then the user is not shown a textfield to input the age > > (because the ref points to an empty nodeset; and the submitted instance > document never contains the <age> element). > > I suppose i could fiddle around with <insert> and <delete> to add/remove > > <age> elements when the user is or is not about to enter his age. But i > hoped that this would not be necessary... > > any ideas??. > thanks a lot in advance!, > gerald > > > ------------------------------------------------------------------------ > > > -- > 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 > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Stephen Bayliss wrote:
> Can you not validate it against the schema at a later stage; ie after > you've removed the empty <age> node? it's of course possible to use XForms without attaching a schema to the model directly (and validate the instance document against the schema at a later stage), but to be honest that's against my primary motivation for using XForms: Given an initial XML-Schema to use XForms to guide the user in interactively creating a valid instance document - with all the beautiful AJAX-style on-the-fly validation and visual feedback that the OPS forms processor provides. Basically, when the forms processor shows no more validation errors on form controls, then the instance document should be guaranteed to be valid against the initial XML-Schema. Not having the XForms model validated against a schema, or using a schema that is less stringent (with respect to optional elements) than the initial schema is counter-productive as it gives the impression to the user that the instance document he produced is valid, while in fact the validation might fail at a later stage after submit. all the best, gerald > > -----Original Message----- > From: Gerald Loeffler [mailto:[hidden email]] > Sent: 07 December 2005 18:45 > To: [hidden email] > Subject: Re: [ops-users] XForms: absent vs. empty elements > > thanks stephen, > > but the problem than is that i can't use the given schema (schema.xsd > below) as the schema for the XForm model, because an existent but empty > <age> element would be invalid against that schema...(or is it not?) > > cheers, > gerald > > Stephen Bayliss wrote: > >>My suggestion would be to use some xslt to get the document into the >>format you want -- ie wherever you submit it to would do this as the >>first step. (Or possibly XUpdate). >> >>-----Original Message----- >>From: Gerald Loeffler [mailto:[hidden email]] >>Sent: 07 December 2005 17:27 >>To: [hidden email] >>Subject: [ops-users] XForms: absent vs. empty elements >> >>dear ops gurus, >> >>i'm struggling with the following and would greatly appreciate any > > help: > >>Suppose i have an XML-Schema that defines an element as optional: >> >>schema.xsd: >> ... >> <element name="age" type="positiveInteger" minOccurs="0" /> >> ... >> >>This schema is used as the schema for an XForms model and a an <input> > > >>is bound to the <age> element as usual: >> >>view.xhtml: >> ... >> <model schema="schema.xsd"> >> ... >> <input ref="age"/> >> ... >> >>I want to achieve that the submitted instance document >> 1. either contains no <age> element (if the user didn't input an > > age) > >>or >> 2. contains a non-empty <age> element (containing the positive >>integer supplier by the user). >> >>My dilemma is this: >> 1. if i supply an XForm instance document with an empty <age> > > element > >>view.xhtml: >> ... >> <model schema="schema.xsd"> >> <instance> >> ... >> <age/> >> ... >> </instance> >> </model> >> >> >>then the user is shown a textfield to input the age. But if he does > > not > >>input any age, then the submitted instance document contains an empty >><age> element - which is not what i want. >> 2. if, on the other hand, i supply an XForm instance document > > without > >>an <age> element then the user is not shown a textfield to input the > > age > >>(because the ref points to an empty nodeset; and the submitted > > instance > >>document never contains the <age> element). >> >>I suppose i could fiddle around with <insert> and <delete> to > > add/remove > >><age> elements when the user is or is not about to enter his age. But > > i > >>hoped that this would not be necessary... >> >> any ideas??. >> thanks a lot in advance!, >> gerald >> >> >> > > ------------------------------------------------------------------------ > >> >>-- >>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 >>ObjectWeb mailing lists service home page: > > http://www.objectweb.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 > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
In reply to this post by Gerald Loeffler
Gerald Loeffler wrote:
> hi Erik, > > i had forgotten that i need a prototype to use <insert> - this > unfortunately means that there is no way to dynamically construct the > instance document to contain exactly the elements i need. > > one more thought: can't i use "relevant" to suppress the submission of > elements which are empty just before submission? So the initial instance > document would contain an empty <age> element, and if the user does not > enter an age, the serialisation of <age> is suppressed by setting > relevant to false just before the instance is submitted. I don't know if > elements with relevant=false are considered for validation against the > schema, though... and is non-relevant. It will be validated while the user interacts with the form, but you won't see associated validation errors since the element is not visible. Upon submission, as per the XForms spec, non-relevant elements are first removed, then validation takes place. So this may actually be a good solution! The only trick is to produce initially extra template elements, and of course add the right xforms:bind to handle relevance. -Erik -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
brilliant - i'll try this (i.e. using "relevant" to deal with optional,
validated elements) and let the list know whether it worked. cheers, gerald Erik Bruchez wrote: > Gerald Loeffler wrote: > >> hi Erik, >> >> i had forgotten that i need a prototype to use <insert> - this >> unfortunately means that there is no way to dynamically construct the >> instance document to contain exactly the elements i need. >> >> one more thought: can't i use "relevant" to suppress the submission of >> elements which are empty just before submission? So the initial >> instance document would contain an empty <age> element, and if the >> user does not enter an age, the serialisation of <age> is suppressed >> by setting relevant to false just before the instance is submitted. I >> don't know if elements with relevant=false are considered for >> validation against the schema, though... > > > Let's assume you have an extra <age> element that works as a template > and is non-relevant. It will be validated while the user interacts with > the form, but you won't see associated validation errors since the > element is not visible. > > Upon submission, as per the XForms spec, non-relevant elements are first > removed, then validation takes place. So this may actually be a good > solution! The only trick is to produce initially extra template > elements, and of course add the right xforms:bind to handle relevance. > > -Erik > > > ------------------------------------------------------------------------ > > > -- > 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 > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws dr. gerald loeffler, enterprise software architect -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Yes, please do. And if it works fine, we should even document this in a
"Validating Forms With XML Schema" section, as this promises to be a fairly common pattern. -Erik Gerald Loeffler wrote: > brilliant - i'll try this (i.e. using "relevant" to deal with optional, > validated elements) and let the list know whether it worked. > > cheers, > gerald > > Erik Bruchez wrote: > >> Gerald Loeffler wrote: >> >>> hi Erik, >>> >>> i had forgotten that i need a prototype to use <insert> - this >>> unfortunately means that there is no way to dynamically construct the >>> instance document to contain exactly the elements i need. >>> >>> one more thought: can't i use "relevant" to suppress the submission >>> of elements which are empty just before submission? So the initial >>> instance document would contain an empty <age> element, and if the >>> user does not enter an age, the serialisation of <age> is suppressed >>> by setting relevant to false just before the instance is submitted. I >>> don't know if elements with relevant=false are considered for >>> validation against the schema, though... >> >> >> >> Let's assume you have an extra <age> element that works as a template >> and is non-relevant. It will be validated while the user interacts >> with the form, but you won't see associated validation errors since >> the element is not visible. >> >> Upon submission, as per the XForms spec, non-relevant elements are >> first removed, then validation takes place. So this may actually be a >> good solution! The only trick is to produce initially extra template >> elements, and of course add the right xforms:bind to handle relevance. >> >> -Erik >> >> >> ------------------------------------------------------------------------ >> >> >> -- >> 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 >> ObjectWeb mailing lists service home page: http://www.objectweb.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 > ObjectWeb mailing lists service home page: http://www.objectweb.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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |