You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Murray Cassie <ca...@yahoo.com> on 2005/01/24 15:39:07 UTC

CForms number validation behaviour

Hi,

we have implemented a range validation like this:

<fd:datatype base="integer"/>
            <fd:label>
            </fd:label>
            <fd:validation>
                <fd:range min="0" max="50000">
                    <fd:failmessage>Valid range is
between 0 and 50000.</fd:failmessage>
                </fd:range>
            </fd:validation>

We get the error message when a number is entered that
is outside the given range and when a string like
"abc" is entered.

Problem: when we enter something like "3abc" this is
treated like a correct entry. All characters after the
first that is no number are cut off and only the first
numbers are evaluated.

This might be wanted behaviour, but not according to
our spec.

Any suggestions how we can change this???

Thanks to all and best regards
Cassie


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms number validation behaviour

Posted by Murray Cassie <ca...@yahoo.com>.
Thanks Vil,

we might have to go for something like this too, but I
think the current default behaviour is not very user
friendly and should be changed generally.

Question to Reinhard:
we are using a fd:range validation based on the
integer datatype, I have not come across an example
how I can combine this with a fd:regexp validation as
this is based on a string datatype.
How do you do this?

Thanks all and best regards
Cassie

--- Vilya Harvey <vi...@gmail.com> wrote:

> Reinhard Poetz wrote:
> 
> > Murray Cassie wrote:
> >
> >> Problem: when we enter something like "3abc" this
> is
> >> treated like a correct entry. All characters
> after the
> >> first that is no number are cut off and only the
> first
> >> numbers are evaluated.
> >>
> >> This might be wanted behaviour, but not according
> to
> >> our spec.
> >>
> >> Any suggestions how we can change this???
> >
> >
> > As a workaround, add a regexp validation that
> makes sure that only 
> > [0-9] is allowed. But the behaviour is strange
> because the datatype 
> > "integer" should make sure that only an integer is
> valid.
> 
> I've just had to deal with exactly the same issue on
> my project at work. 
> The problem is actually the NumberFormat class which
> does the parsing. 
> The JavaDocs don't make it very clear, but what it
> does is parse only 
> the leading digits in the string rather than the
> whole string. The same 
> problem applies with decimal, float and double
> datatypes as well.
> 
> I worked around the problem by implementing my own
> converter classes and 
> changing the cocoon.xconf file to use those by
> default instead. Each of 
> the new converters uses the NumberFormat.parse()
> method which takes a 
> ParsePosition as well as a String; after parsing,
> they simply check that 
> the ParsePosition is at the end of the input string.
> 
> The only problem I encountered with doing this is
> that the NumberFormat 
> used by the existing converter infrastructure is a
> wrapper around the 
> JDK one and doesn't expose the parse(String,
> ParsePosition) method. The 
> two options are: switch to using only the JDK
> NumberFormat class, or add 
> the method to the interface. I went for the former,
> as it meant the 
> smallest impact on the Cocoon code.
> 
> Hope that helps,
> 
> Vil.
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms number validation behaviour

Posted by Vilya Harvey <vi...@gmail.com>.
Reinhard Poetz wrote:

> Murray Cassie wrote:
>
>> Problem: when we enter something like "3abc" this is
>> treated like a correct entry. All characters after the
>> first that is no number are cut off and only the first
>> numbers are evaluated.
>>
>> This might be wanted behaviour, but not according to
>> our spec.
>>
>> Any suggestions how we can change this???
>
>
> As a workaround, add a regexp validation that makes sure that only 
> [0-9] is allowed. But the behaviour is strange because the datatype 
> "integer" should make sure that only an integer is valid.

I've just had to deal with exactly the same issue on my project at work. 
The problem is actually the NumberFormat class which does the parsing. 
The JavaDocs don't make it very clear, but what it does is parse only 
the leading digits in the string rather than the whole string. The same 
problem applies with decimal, float and double datatypes as well.

I worked around the problem by implementing my own converter classes and 
changing the cocoon.xconf file to use those by default instead. Each of 
the new converters uses the NumberFormat.parse() method which takes a 
ParsePosition as well as a String; after parsing, they simply check that 
the ParsePosition is at the end of the input string.

The only problem I encountered with doing this is that the NumberFormat 
used by the existing converter infrastructure is a wrapper around the 
JDK one and doesn't expose the parse(String, ParsePosition) method. The 
two options are: switch to using only the JDK NumberFormat class, or add 
the method to the interface. I went for the former, as it meant the 
smallest impact on the Cocoon code.

Hope that helps,

Vil.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms number validation behaviour

Posted by Murray Cassie <ca...@yahoo.com>.
Hi Reinhard,

how would you suggest to combine a validation based on
a string datatype (regex) with a validation based on
an integer (range) for the same field???

Thanks
Cassie
--- Reinhard Poetz <re...@apache.org> wrote:

> Murray Cassie wrote:
> > Hi,
> > 
> > we have implemented a range validation like this:
> > 
> > <fd:datatype base="integer"/>
> >             <fd:label>
> >             </fd:label>
> >             <fd:validation>
> >                 <fd:range min="0" max="50000">
> >                     <fd:failmessage>Valid range is
> > between 0 and 50000.</fd:failmessage>
> >                 </fd:range>
> >             </fd:validation>
> > 
> > We get the error message when a number is entered
> that
> > is outside the given range and when a string like
> > "abc" is entered.
> > 
> > Problem: when we enter something like "3abc" this
> is
> > treated like a correct entry. All characters after
> the
> > first that is no number are cut off and only the
> first
> > numbers are evaluated.
> > 
> > This might be wanted behaviour, but not according
> to
> > our spec.
> > 
> > Any suggestions how we can change this???
> 
> As a workaround, add a regexp validation that makes
> sure that only [0-9] is 
> allowed. But the behaviour is strange because the
> datatype "integer" should make 
> sure that only an integer is valid.
> 
> -- 
> Reinhard
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms number validation behaviour

Posted by Reinhard Poetz <re...@apache.org>.
Murray Cassie wrote:
> Hi,
> 
> we have implemented a range validation like this:
> 
> <fd:datatype base="integer"/>
>             <fd:label>
>             </fd:label>
>             <fd:validation>
>                 <fd:range min="0" max="50000">
>                     <fd:failmessage>Valid range is
> between 0 and 50000.</fd:failmessage>
>                 </fd:range>
>             </fd:validation>
> 
> We get the error message when a number is entered that
> is outside the given range and when a string like
> "abc" is entered.
> 
> Problem: when we enter something like "3abc" this is
> treated like a correct entry. All characters after the
> first that is no number are cut off and only the first
> numbers are evaluated.
> 
> This might be wanted behaviour, but not according to
> our spec.
> 
> Any suggestions how we can change this???

As a workaround, add a regexp validation that makes sure that only [0-9] is 
allowed. But the behaviour is strange because the datatype "integer" should make 
sure that only an integer is valid.

-- 
Reinhard

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org