Order of xforms-recalculate and xforms-revalidate events

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

Order of xforms-recalculate and xforms-revalidate events

Robby Cornelissen
I'm relatively new to Orbeon and XForms in general, and I'm stumped by a seemingly simple problem. I've created the following test form:

<xhtml:html                                                                                                                                                                                                            xmlns:xforms="http://www.w3.org/2002/xforms"                                                                                                                                                                       xmlns:xhtml="http://www.w3.org/1999/xhtml"                                                                                                                                                                    
    xmlns:xs="http://www.w3.org/2001/XMLSchema">                                                                                                                                                                  
    <xhtml:head>                                                                                                                                                                                                  
        <xhtml:title>Validation-Calculation-Order</xhtml:title>                                                                                                                                                    
        <xforms:model>                                                                                                                                                                                            
            <xforms:instance id="example" xmlns="">                                                                                                                                                                                <example>                                                                                                                                                                                                              <value1>10</value1>                                                                                                                                                                            
                    <value2>10</value2>                                                                                                                                                                                                <value3>100</value3>                                                                                                                                                                          
                </example>                                                                                                                                                                                        
            </xforms:instance>                                                                                                                                                                                    
            <xforms:bind nodeset="value1" type="xs:integer"/>                                                                                                                                                                  <xforms:bind nodeset="value2" type="xs:integer"/>                                                                                                                                                                  <xforms:bind nodeset="value3" type="xs:integer" calculate="../value1 * ../value2"/>                                                                                                                    
        </xforms:model>                                                                                                                                                                                            
    </xhtml:head>                                                                                                                                                                                                  
    <xhtml:body>                                                                                                                                                                                                  
        <xforms:input ref="value1"/>                                                                                                                                                                              
        <xforms:input ref="value2"/>                                                                                                                                                                              
        <xforms:output ref="value3"/>                                                                                                                                                                              
    </xhtml:body>                                                                                                                                                                                                  
</xhtml:html>

Basically, the idea is to recalculate value3 whenever the user changes value1 or value2. The problem is that, if the users enters a value that is not numeric, I get a 'Failure converting untyped value "a" to a number' after evaluation of the calculate bind. So the question is, how can I force revalidation to occur before recalculation without resorting to xforms:setvalue and the likes?

Cheers,

Darth


--
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: Order of xforms-recalculate and xforms-revalidate events

Hank Ratzesberger

Hi,

Perhaps the XPath 2.0 castable function, so that the calculation is not
attempted if the content is not valid.

   calculate="if ((../value1 castable as xs:integer) and (../value2  
castable as xs:integer))
      ../value1 * ../value2"

(hopefully this code works, if you grep for castable in the source  
examples, you will
see others known to work...)

http://www.w3.org/TR/xpath20/#id-castable

Cheers,
Hank

On Jun 26, 2008, at 7:45 AM, Robby Cornelissen wrote:

> I'm relatively new to Orbeon and XForms in general, and I'm stumped  
> by a seemingly simple problem. I've created the following test form:
>
> <xhtml:html                                                            
>                                                                        
>                                                                        
>      xmlns:xforms="http://www.w3.org/2002/ 
> xforms"                                                                
>                                                                        
>                                   xmlns:xhtml="http://www.w3.org/ 
> 1999/xhtml"
>     xmlns:xs="http://www.w3.org/2001/XMLSchema">
>     <xhtml:head>
>         <xhtml:title>Validation-Calculation-Order</xhtml:title>
>         <xforms:model>
>             <xforms:instance id="example"  
> xmlns="">                                                              
>                                                                        
>                                              
> <example>                                                              
>                                                                        
>                                                                        
>      <value1>10</value1>
>                     <value2>10</
> value2>                                                                
>                                                                        
>                                                            
> <value3>100</value3>
>                 </example>
>             </xforms:instance>
>             <xforms:bind nodeset="value1" type="xs:integer"/
> >                                                                      
>                                                                        
>                        <xforms:bind nodeset="value2"  
> type="xs:integer"/
> >                                                                      
>                                                                        
>                        <xforms:bind nodeset="value3"  
> type="xs:integer" calculate="../value1 * ../value2"/>
>         </xforms:model>
>     </xhtml:head>
>     <xhtml:body>
>         <xforms:input ref="value1"/>
>         <xforms:input ref="value2"/>
>         <xforms:output ref="value3"/>
>     </xhtml:body>
> </xhtml:html>
>
> Basically, the idea is to recalculate value3 whenever the user  
> changes value1 or value2. The problem is that, if the users enters  
> a value that is not numeric, I get a 'Failure converting untyped  
> value "a" to a number' after evaluation of the calculate bind. So  
> the question is, how can I force revalidation to occur before  
> recalculation without resorting to xforms:setvalue and the likes?
>
> Cheers,
>
> Darth
>
> --
> 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
Hank Ratzesberger
NEES@UCSB
Institute for Crustal Studies,
University of California, Santa Barbara
805-893-8042







--
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: Order of xforms-recalculate and xforms-revalidate events

Erik Bruchez
Administrator
Yes, that's the idea. A little annoying but I am not sure there is a  
better way to avoid conversion errors at the moment.

However I don't think we should propagate dynamic JS errors to the  
client the way we do now. We need to check this. The issue is that w/  
XForms/XPath 1.0, this can't really happen, but in XPath 2.0 more  
dynamic errors can happen. I entered an RFE to track this:

   http://tinyurl.com/6luw7s

Regarding forcing a revalidation, I am not sure this will help. What  
did you have in mind?

-Erik

On Jun 26, 2008, at 8:21 AM, Hank Ratzesberger wrote:

>
> Hi,
>
> Perhaps the XPath 2.0 castable function, so that the calculation is  
> not
> attempted if the content is not valid.
>
>  calculate="if ((../value1 castable as xs:integer) and (../value2  
> castable as xs:integer))
>     ../value1 * ../value2"
>
> (hopefully this code works, if you grep for castable in the source  
> examples, you will
> see others known to work...)
>
> http://www.w3.org/TR/xpath20/#id-castable
>
> Cheers,
> Hank
>
> On Jun 26, 2008, at 7:45 AM, Robby Cornelissen wrote:
>
>> I'm relatively new to Orbeon and XForms in general, and I'm stumped  
>> by a seemingly simple problem. I've created the following test form:
>>
>> <
>> xhtml:html
>>                                                                                                                                                                                                             xmlns:xforms
>> ="http://www.w3.org/2002/ 
>> xforms
>> "                                                                                                                                                                       xmlns:xhtml
>> ="http://www.w3.org/1999/xhtml"
>>    xmlns:xs="http://www.w3.org/2001/XMLSchema">
>>    <xhtml:head>
>>        <xhtml:title>Validation-Calculation-Order</xhtml:title>
>>        <xforms:model>
>>            <xforms:instance id="example"  
>> xmlns
>> =
>> "">
>>                                                                                                                                                                                 <
>> example
>> >
>>                                                                                                                                                                                                               <
>> value1>10</value1>
>>                    <value2>10</
>> value2
>> >
>>                                                                                                                                                                                                 <
>> value3>100</value3>
>>                </example>
>>            </xforms:instance>
>>            <xforms:bind nodeset="value1" type="xs:integer"/
>> >
>>                                                                                                                                                                   <
>> xforms:bind nodeset="value2" type="xs:integer"/
>> >
>>                                                                                                                                                                   <
>> xforms:bind nodeset="value3" type="xs:integer" calculate="../value1  
>> * ../value2"/>
>>        </xforms:model>
>>    </xhtml:head>
>>    <xhtml:body>
>>        <xforms:input ref="value1"/>
>>        <xforms:input ref="value2"/>
>>        <xforms:output ref="value3"/>
>>    </xhtml:body>
>> </xhtml:html>
>>
>> Basically, the idea is to recalculate value3 whenever the user  
>> changes value1 or value2. The problem is that, if the users enters  
>> a value that is not numeric, I get a 'Failure converting untyped  
>> value "a" to a number' after evaluation of the calculate bind. So  
>> the question is, how can I force revalidation to occur before  
>> recalculation without resorting to xforms:setvalue and the likes?
>>
>> Cheers,
>>
>> Darth
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.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
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

Robby Cornelissen
I'll go with the castable check for now. Like I said, I'm pretty knew to XForms, so I'm not really sure what I had in mind. I've written a couple of form frameworks in Javascript in the past, and in those I checked data types and constraints before attempting calculations. In the Orbeon docs, I found something about an xxforms:computed-binds="revalidate" MIP which sounded pretty much like what I was looking for, but didn't do the trick.

Thanks for the effort and the great work, and I'll hope to be able to provide more substantial input when I get the hang of things.

Darth

On Thu, Jun 26, 2008 at 07:50:00PM -0700, Erik Bruchez wrote:

> Yes, that's the idea. A little annoying but I am not sure there is a  
> better way to avoid conversion errors at the moment.
>
> However I don't think we should propagate dynamic JS errors to the  
> client the way we do now. We need to check this. The issue is that w/  
> XForms/XPath 1.0, this can't really happen, but in XPath 2.0 more  
> dynamic errors can happen. I entered an RFE to track this:
>
>   http://tinyurl.com/6luw7s
>
> Regarding forcing a revalidation, I am not sure this will help. What  
> did you have in mind?
>
> -Erik
>
> On Jun 26, 2008, at 8:21 AM, Hank Ratzesberger wrote:
>
> >
> >Hi,
> >
> >Perhaps the XPath 2.0 castable function, so that the calculation is  
> >not
> >attempted if the content is not valid.
> >
> > calculate="if ((../value1 castable as xs:integer) and (../value2  
> >castable as xs:integer))
> >    ../value1 * ../value2"
> >
> >(hopefully this code works, if you grep for castable in the source  
> >examples, you will
> >see others known to work...)
> >
> >http://www.w3.org/TR/xpath20/#id-castable
> >
> >Cheers,
> >Hank
> >
> >On Jun 26, 2008, at 7:45 AM, Robby Cornelissen wrote:
> >
> >>I'm relatively new to Orbeon and XForms in general, and I'm stumped  
> >>by a seemingly simple problem. I've created the following test form:
> >>
> >><
> >>xhtml:html
> >>                                                                                                                                                                                                            xmlns:xforms ="http://www.w3.org/2002/ 
> >>xforms
> >>"                                                                        
> >>xmlns:xhtml ="http://www.w3.org/1999/xhtml"
> >>   xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >>   <xhtml:head>
> >>       <xhtml:title>Validation-Calculation-Order</xhtml:title>
> >>       <xforms:model>
> >>           <xforms:instance id="example"  
> >>xmlns
> >>=
> >>"">
> >>                                                                                                                                                                                < example
> >>>
> >>                                                                                                                                                                                                              < value1>10</value1>
> >>                   <value2>10</
> >>value2
> >>>
> >>                                                                                                                                                                                                < value3>100</value3>
> >>               </example>
> >>           </xforms:instance>
> >>           <xforms:bind nodeset="value1" type="xs:integer"/
> >>>
> >>                                                                                                                                                                  < xforms:bind nodeset="value2" type="xs:integer"/
> >>>
> >>                                                                                                                                                                  < xforms:bind nodeset="value3" type="xs:integer" calculate="../value1  
> >>* ../value2"/>
> >>       </xforms:model>
> >>   </xhtml:head>
> >>   <xhtml:body>
> >>       <xforms:input ref="value1"/>
> >>       <xforms:input ref="value2"/>
> >>       <xforms:output ref="value3"/>
> >>   </xhtml:body>
> >></xhtml:html>
> >>
> >>Basically, the idea is to recalculate value3 whenever the user  
> >>changes value1 or value2. The problem is that, if the users enters  
> >>a value that is not numeric, I get a 'Failure converting untyped  
> >>value "a" to a number' after evaluation of the calculate bind. So  
> >>the question is, how can I force revalidation to occur before  
> >>recalculation without resorting to xforms:setvalue and the likes?
> >>
> >>Cheers,
> >>
> >>Darth
>
> --
> Orbeon Forms - Web Forms for the Enterprise Done the Right Way
> http://www.orbeon.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



--
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: Re: Order of xforms-recalculate and xforms-revalidate events

stessy
Sorry to bump that message, but I'm encountering the same problem.

Even if I follow what Hank proposes, the error message appears

Here is what I try to do

<xforms:bind nodeset="instance('FORM.FP7CP.1.A3_1')/pers_cost"
                        calculate="
                                if((instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd castable as xs:integer)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__demo castable as xs:integer)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__mng castable as xs:integer)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__oth castable as xs:integer))
                                then
                                        (instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__demo+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__mng+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__oth)
                                        else()"
                                        />

If the field is empty or is not a numeric value, I catch the error message, which is a bit annoying.

Tried as well by adding an additional check on field length with same behaviour.

<xforms:bind nodeset="instance('FORM.FP7CP.1.A3_1')/pers_cost"
                        calculate="
                                if((instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd castable as xs:integer and string-length(instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd) > 0)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__demo castable as xs:integer)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__mng castable as xs:integer)
                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__oth castable as xs:integer))
                                then
                                        (instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__demo+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__mng+
                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__oth)
                                        else()"
                                        />

Do you have any advice to prevent from displaying the error message ??

Thanks a lot for your help

Regards,
Stessy
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

Alessandro  Vernet
Administrator
Stessy,

The tests you are doing in that calculate expression  look good to me,
and I don't see why you would get an error there. Are you sure that
you are not getting this error for another calculate="..."? If not,
could you create a simple test case we can run the XForms sandbox to
reproduce this?

Alex

On Wed, Mar 24, 2010 at 7:53 AM, stessy <[hidden email]> wrote:

>
> Sorry to bump that message, but I'm encountering the same problem.
>
> Even if I follow what Hank proposes, the error message appears
>
> Here is what I try to do
>
> <xforms:bind nodeset="instance('FORM.FP7CP.1.A3_1')/pers_cost"
>                        calculate="
>                                if((instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd castable as xs:integer)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__demo castable as
> xs:integer)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__mng castable as
> xs:integer)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__oth castable as
> xs:integer))
>                                then
>                                        (instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__demo+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__mng+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__oth)
>                                        else()"
>                                        />
>
> If the field is empty or is not a numeric value, I catch the error message,
> which is a bit annoying.
>
> Tried as well by adding an additional check on field length with same
> behaviour.
>
> <xforms:bind nodeset="instance('FORM.FP7CP.1.A3_1')/pers_cost"
>                        calculate="
>                                if((instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd castable as xs:integer
> and string-length(instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd) > 0)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__demo castable as
> xs:integer)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__mng castable as
> xs:integer)
>                                and (instance('FORM.FP7CP.1.A3_1')/pers_cost__oth castable as
> xs:integer))
>                                then
>                                        (instance('FORM.FP7CP.1.A3_1')/pers_cost__rtd+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__demo+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__mng+
>                                        instance('FORM.FP7CP.1.A3_1')/pers_cost__oth)
>                                        else()"
>                                        />
>
> Do you have any advice to prevent from displaying the error message ??
>
> Thanks a lot for your help
>
> Regards,
> Stessy
> --
> View this message in context: http://n4.nabble.com/Order-of-xforms-recalculate-and-xforms-revalidate-events-tp35185p1680654.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
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
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
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

stessy
Hi Alessandro,

Here is the file you can test.
The calculation check is done on the first line.

A3.1.xhtml

Regards,
Stessy
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

Alessandro  Vernet
Administrator
Stessy,

I can load the page fine (http://screencast.com/t/MTU4OTNlYm). What
should I do to reproduce the error you're seeing?

Alex

On Thu, Mar 25, 2010 at 12:40 AM, stessy <[hidden email]> wrote:

>
> Hi Alessandro,
>
> Here is the file you can test
>
> http://n4.nabble.com/file/n1690261/A3.1.xhtml A3.1.xhtml
>
> Regards,
> Stessy
>
> --
> View this message in context: http://n4.nabble.com/Order-of-xforms-recalculate-and-xforms-revalidate-events-tp35185p1690261.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
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
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
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

stessy
Alessandro,

the problem occurs when I empty one of the fields on the first line.

Would it be possible not to display the error message and not perform the calculation when a field is emptied after the form is loaded??

That's what my check tries to do without success.


Thanks,
Stessy
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

Alessandro  Vernet
Administrator
Stessy,

I see. The problem is not with that expression computing
instance('FORM.FP7CP.1.A3_1')/pers_cost that has all the castable as
xs:integer. If you comment the other binds that follow, your example
will work fine, so I think you'll need to put some tests on those
expressions as well.

Alex

On Fri, Mar 26, 2010 at 12:17 AM, stessy <[hidden email]> wrote:

>
> Alessandro,
>
> the problem occurs when I empty one of the fields on the first line.
>
> Would it be possible not to display the error message and not perform the
> calculation when a field is emptied after the form is loaded??
>
> That's what my check tries to do without success.
>
>
> Thanks,
> Stessy
> --
> View this message in context: http://n4.nabble.com/Order-of-xforms-recalculate-and-xforms-revalidate-events-tp35185p1691779.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
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
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
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: Re: Order of xforms-recalculate and xforms-revalidate events

stessy
Alex,

thanks for your help.

That was a noob question. I saw my problem. I had completely forgotten that some calculation were done vertically.

Regards,
Stessy