deriving datatype from data?

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

deriving datatype from data?

Adrian Baker-2
Is there any way for the datatype of a node in a repeat to be dynamic
rather than fixed for the entire column?

I have a form which requires a dynamic table (users can add & remove
items), which is achieved easily enough using a repeat in XForms.
However in this case one of the controls on the repeating row does not
have a fixed datatype, rather it's determined by another data value on
the same row. So the instance data might look a bit like this, where
<condition> is the repeating node (and <fieldDataType> is probably not
displayed to the user):

<query>
    <condition>
       <field>diagnosis</field>
       <fieldDataType>xs:string</fieldDataType>
       <comparison>equals</comparison>
       <value>DIAB001</value>
    </condition>
    <condition>
       <field>lengthOfProcedure</field>
       <fieldDataType>xs:integer</fieldDataType>
       <comparison>greaterThan</comparison>
       <value>60</value>
    </condition>
    <condition>
       <field>admissionDate</field>
       <fieldDataType>xs:dateTimefieldDataType>
       <comparison>greaterThan</comparison>
       <value>2005-11-24T10:20:00+12:00</value>
    </condition>
</query>

When a row is added, field & fieldDataType are set at the time of
addition - they can't be changed once on the table, only comparison &
value are editable in a row.

Now, in this case it's obviously desirable for the control bound to
<value> to present & restrict the data entry based on <fieldDataType>
ie, if the condition is on an integer, <value> should only accept
integers. If it's a date, the date should be formatted and the calendar
be available to choose a date.

Sadly I can't see any way to achieve this in XForms though, because I
can only bind once to each field under <condition>, and the datatype is
fixed for the bind.

If the <query> instance was static rather than dynamic, I could use a
XSLT on the form prior to display to generate the appropriate datatype
bindings, but that means you can't add <condition> nodes from the form.

Alternatively, I can probably make the constraint xpath on the bind
fairly complex, and work off <fieldDataType> to lookup the correct XPath
2.0 function to validate the input. This takes care of validation, but
it means things like dates have to be input in their native xml schema
format, because the XForms engine isn't aware of the datatype - ugh!

Another approach would be the expensive (and horrible) hack of
generating a copy of <condition> for every possible datatype, then
making only the appropriate one relevant. Surely there is a better
way... Is there a way to (dynamically) provide a hint to OPS to present
a control as having a particular datatype?

Adrian





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

Re: deriving datatype from data?

Erik Bruchez
Administrator
Adrian,

What about something like:

<xforms:bind nodeset="//field[../fieldDataType = 'xs:string']"
              type="xs:string"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:integer']"
              nodeset="" type="xs:integer"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:dateTime']"
              nodeset="" type="xs:dateTime"/>

?

Technically, this is a dynamical dependency which may require
xforms:rebuild to update, but it should work with OPS.

-Erik

Adrian Baker wrote:

> Is there any way for the datatype of a node in a repeat to be dynamic
> rather than fixed for the entire column?
>
> I have a form which requires a dynamic table (users can add & remove
> items), which is achieved easily enough using a repeat in XForms.
> However in this case one of the controls on the repeating row does not
> have a fixed datatype, rather it's determined by another data value on
> the same row. So the instance data might look a bit like this, where
> <condition> is the repeating node (and <fieldDataType> is probably not
> displayed to the user):
>
> <query>
>    <condition>
>       <field>diagnosis</field>
>       <fieldDataType>xs:string</fieldDataType>
>       <comparison>equals</comparison>
>       <value>DIAB001</value>
>    </condition>
>    <condition>
>       <field>lengthOfProcedure</field>
>       <fieldDataType>xs:integer</fieldDataType>
>       <comparison>greaterThan</comparison>
>       <value>60</value>
>    </condition>
>    <condition>
>       <field>admissionDate</field>
>       <fieldDataType>xs:dateTimefieldDataType>
>       <comparison>greaterThan</comparison>
>       <value>2005-11-24T10:20:00+12:00</value>
>    </condition>
> </query>
>
> When a row is added, field & fieldDataType are set at the time of
> addition - they can't be changed once on the table, only comparison &
> value are editable in a row.
>
> Now, in this case it's obviously desirable for the control bound to
> <value> to present & restrict the data entry based on <fieldDataType>
> ie, if the condition is on an integer, <value> should only accept
> integers. If it's a date, the date should be formatted and the calendar
> be available to choose a date.
>
> Sadly I can't see any way to achieve this in XForms though, because I
> can only bind once to each field under <condition>, and the datatype is
> fixed for the bind.
>
> If the <query> instance was static rather than dynamic, I could use a
> XSLT on the form prior to display to generate the appropriate datatype
> bindings, but that means you can't add <condition> nodes from the form.
>
> Alternatively, I can probably make the constraint xpath on the bind
> fairly complex, and work off <fieldDataType> to lookup the correct XPath
> 2.0 function to validate the input. This takes care of validation, but
> it means things like dates have to be input in their native xml schema
> format, because the XForms engine isn't aware of the datatype - ugh!
>
> Another approach would be the expensive (and horrible) hack of
> generating a copy of <condition> for every possible datatype, then
> making only the appropriate one relevant. Surely there is a better
> way... Is there a way to (dynamically) provide a hint to OPS to present
> a control as having a particular datatype?
>
> Adrian



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

Re: deriving datatype from data?

Adrian Baker-2
Finally got back to looking at this: yes, this works fine: thanks for the suggestion Erik.

It's a pity the spec (as I read it) actually states these expressions aren't allowed, rather than just suggesting that rebuilds have to be triggered manually when dynamic dependencies are used - certainly I'm glad OPS supports this, because otherwise we'd have to resort to doing the screen with regular HTML+Javascript.

Hopefully this restriction might be relaxed in a later version of the specification?

Adrian

Erik Bruchez wrote:
Adrian,

What about something like:

<xforms:bind nodeset="//field[../fieldDataType = 'xs:string']"
             type="xs:string"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:integer']"
             nodeset="" type="xs:integer"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:dateTime']"
             nodeset="" type="xs:dateTime"/>

?

Technically, this is a dynamical dependency which may require xforms:rebuild to update, but it should work with OPS.

-Erik

Adrian Baker wrote:
Is there any way for the datatype of a node in a repeat to be dynamic rather than fixed for the entire column?

I have a form which requires a dynamic table (users can add & remove items), which is achieved easily enough using a repeat in XForms. However in this case one of the controls on the repeating row does not have a fixed datatype, rather it's determined by another data value on the same row. So the instance data might look a bit like this, where <condition> is the repeating node (and <fieldDataType> is probably not displayed to the user):

<query>
   <condition>
      <field>diagnosis</field>
      <fieldDataType>xs:string</fieldDataType>
      <comparison>equals</comparison>
      <value>DIAB001</value>
   </condition>
   <condition>
      <field>lengthOfProcedure</field>
      <fieldDataType>xs:integer</fieldDataType>
      <comparison>greaterThan</comparison>
      <value>60</value>
   </condition>
   <condition>
      <field>admissionDate</field>
      <fieldDataType>xs:dateTimefieldDataType>
      <comparison>greaterThan</comparison>
      <value>2005-11-24T10:20:00+12:00</value>
   </condition>
</query>

When a row is added, field & fieldDataType are set at the time of addition - they can't be changed once on the table, only comparison & value are editable in a row.

Now, in this case it's obviously desirable for the control bound to <value> to present & restrict the data entry based on <fieldDataType> ie, if the condition is on an integer, <value> should only accept integers. If it's a date, the date should be formatted and the calendar be available to choose a date.

Sadly I can't see any way to achieve this in XForms though, because I can only bind once to each field under <condition>, and the datatype is fixed for the bind.

If the <query> instance was static rather than dynamic, I could use a XSLT on the form prior to display to generate the appropriate datatype bindings, but that means you can't add <condition> nodes from the form.

Alternatively, I can probably make the constraint xpath on the bind fairly complex, and work off <fieldDataType> to lookup the correct XPath 2.0 function to validate the input. This takes care of validation, but it means things like dates have to be input in their native xml schema format, because the XForms engine isn't aware of the datatype - ugh!

Another approach would be the expensive (and horrible) hack of generating a copy of <condition> for every possible datatype, then making only the appropriate one relevant. Surely there is a better way... Is there a way to (dynamically) provide a hint to OPS to present a control as having a particular datatype?

Adrian



-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

RE: deriving datatype from data?

Richard Braman
Message
Is there a way to get the datatype when you instance is bound to a schema instead?
 
putting xs:integer around all of the nodelists in my xPath expressions is a pain.  it would be nice for OPS XPath engine to know what datatype a particular node is.
 
-----Original Message-----
From: Adrian Baker [mailto:[hidden email]]
Sent: Saturday, March 04, 2006 12:06 AM
To: [hidden email]
Subject: Re: [ops-users] deriving datatype from data?

Finally got back to looking at this: yes, this works fine: thanks for the suggestion Erik.

It's a pity the spec (as I read it) actually states these expressions aren't allowed, rather than just suggesting that rebuilds have to be triggered manually when dynamic dependencies are used - certainly I'm glad OPS supports this, because otherwise we'd have to resort to doing the screen with regular HTML+Javascript.

Hopefully this restriction might be relaxed in a later version of the specification?

Adrian

Erik Bruchez wrote:
Adrian,

What about something like:

<xforms:bind nodeset="//field[../fieldDataType = 'xs:string']"
             type="xs:string"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:integer']"
             nodeset="" type="xs:integer"/>
<xforms:bind nodeset="//field[../fieldDataType = 'xs:dateTime']"
             nodeset="" type="xs:dateTime"/>

?

Technically, this is a dynamical dependency which may require xforms:rebuild to update, but it should work with OPS.

-Erik

Adrian Baker wrote:
Is there any way for the datatype of a node in a repeat to be dynamic rather than fixed for the entire column?

I have a form which requires a dynamic table (users can add & remove items), which is achieved easily enough using a repeat in XForms. However in this case one of the controls on the repeating row does not have a fixed datatype, rather it's determined by another data value on the same row. So the instance data might look a bit like this, where <condition> is the repeating node (and <fieldDataType> is probably not displayed to the user):

<query>
   <condition>
      <field>diagnosis</field>
      <fieldDataType>xs:string</fieldDataType>
      <comparison>equals</comparison>
      <value>DIAB001</value>
   </condition>
   <condition>
      <field>lengthOfProcedure</field>
      <fieldDataType>xs:integer</fieldDataType>
      <comparison>greaterThan</comparison>
      <value>60</value>
   </condition>
   <condition>
      <field>admissionDate</field>
      <fieldDataType>xs:dateTimefieldDataType>
      <comparison>greaterThan</comparison>
      <value>2005-11-24T10:20:00+12:00</value>
   </condition>
</query>

When a row is added, field & fieldDataType are set at the time of addition - they can't be changed once on the table, only comparison & value are editable in a row.

Now, in this case it's obviously desirable for the control bound to <value> to present & restrict the data entry based on <fieldDataType> ie, if the condition is on an integer, <value> should only accept integers. If it's a date, the date should be formatted and the calendar be available to choose a date.

Sadly I can't see any way to achieve this in XForms though, because I can only bind once to each field under <condition>, and the datatype is fixed for the bind.

If the <query> instance was static rather than dynamic, I could use a XSLT on the form prior to display to generate the appropriate datatype bindings, but that means you can't add <condition> nodes from the form.

Alternatively, I can probably make the constraint xpath on the bind fairly complex, and work off <fieldDataType> to lookup the correct XPath 2.0 function to validate the input. This takes care of validation, but it means things like dates have to be input in their native xml schema format, because the XForms engine isn't aware of the datatype - ugh!

Another approach would be the expensive (and horrible) hack of generating a copy of <condition> for every possible datatype, then making only the appropriate one relevant. Surely there is a better way... Is there a way to (dynamically) provide a hint to OPS to present a control as having a particular datatype?

Adrian



-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] 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