You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Brian Long <br...@gmail.com> on 2006/02/17 18:46:36 UTC

Minimum and Maximum Validators in 4.0

Hi guys,

I've spend this afternoon trying to get the minimum and maximum validators
for Tapestry 4.0 to work without success.

I have a TextField component with an associated FieldLabel component onto
which I attach the Min and Max validators :

<td>
<label jwcid="@FieldLabel" field="component:dummyTextField" displayName=
"DummyTextField">DummyTextField</label>
</td>
<td>
<input jwcid="dummyTextField@TextField" value="ognl:amount"
validators="validators:min=15,max=5000"
size="10" />
</td>

Pretty straightforward, or so you'd think! The problem is that I get a Class
Cast Exception when I run the application

>>java.lang.ClassCastException
>>java.lang.String

in Tapestry and I enter data into this textfield and submit the form. The
problem is that the validate method in Min Class (
org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you can
see it's trying to cast the contents of the received
Object to an Number, the problem it that this Object Contains a String,
well, we are using a TextField component after all?

public void validate(IFormComponent field, ValidationMessages messages,
Object object)
            throws ValidatorException
    {
        Number value = (Number) object;

        if (_min > value.doubleValue())
            throw new ValidatorException(buildMessage(messages, field),
                    ValidationConstraint.TOO_SMALL);
    }

Now I know that you can't cast from a String to a Number,Integer,BigDecimal
etc, but it's an Object we're casting from. I
know that it contains a string, but its a numeric string i.e "123", is it
that the Min class is at fault here or is it something I'm
doing wrong?

If Jesse Kuhnert is reading this and has five minutes to deliver the answer
to my question it would be much appreciated.

Brian Long.

Re: Minimum and Maximum Validators in 4.0

Posted by Paul Ferraro <pm...@columbia.edu>.
You will want to use the following translator binding:

translator="translator:number"

Paul

Howard Lewis Ship wrote:
> At the root of this is that the value comes up as a string, and if you
> don't tell Tapestry otherwise, it stays a string ... but needs to be a
> Number for max and min validators.
>
> The translator parameter controls this.  You want to use
> "translator:int" (I believe, check the docs). This will convert int
> property on the server side to a string, and vice-versa.
>
> On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
>   
>> I meant more like the sample given in the translator parameter here (
>> http://jakarta.apache.org/tapestry/tapestry/ComponentReference/DatePicker.html
>> ).
>>
>>
>>
>> On 2/17/06, Brian Long <br...@gmail.com> wrote:
>>     
>>> Jesse,
>>>
>>> do you mean like this?
>>>
>>> <input jwcid="dummyTextField@TextField" value="translator:ognl:amount"
>>> validators="validators:min=15,max=5000" size="10" />
>>>
>>> Regards, Brian.
>>>
>>> On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
>>>       
>>>> Oh, try adding the translator: binding as well :)
>>>>
>>>> On 2/17/06, Brian Long <br...@gmail.com> wrote:
>>>>         
>>>>> Jesse,
>>>>>
>>>>> thanks for the quick reply, but I have bound the value to
>>>>> "ognl:amount", which is a BigDecimal (a subclass of Number) used in my
>>>>> java class? Is this a step to far for the Compiler/Tapestry framework,
>>>>> because if what you say is true, this should have worked.
>>>>>
>>>>> Brian.
>>>>>
>>>>> On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
>>>>>           
>>>>>> You need to have you value binding for TextField be either a Numeric
>>>>>>             
>>>>> object
>>>>>           
>>>>>> type or native numeric value.  That's just the way it is for
>>>>>>             
>>> now...Won't
>>>       
>>>>> be
>>>>>           
>>>>>> in tap4.1...
>>>>>>
>>>>>>
>>>>>> On 2/17/06, Brian Long <br...@gmail.com> wrote:
>>>>>>             
>>>>>>> Hi guys,
>>>>>>>
>>>>>>> I've spend this afternoon trying to get the minimum and maximum
>>>>>>>               
>>>>> validators
>>>>>           
>>>>>>> for Tapestry 4.0 to work without success.
>>>>>>>
>>>>>>> I have a TextField component with an associated FieldLabel
>>>>>>>               
>>> component
>>>       
>>>>> onto
>>>>>           
>>>>>>> which I attach the Min and Max validators :
>>>>>>>
>>>>>>> <td>
>>>>>>> <label jwcid="@FieldLabel" field="component:dummyTextField"
>>>>>>>               
>>>>> displayName=
>>>>>           
>>>>>>> "DummyTextField">DummyTextField</label>
>>>>>>> </td>
>>>>>>> <td>
>>>>>>> <input jwcid="dummyTextField@TextField" value="ognl:amount"
>>>>>>> validators="validators:min=15,max=5000"
>>>>>>> size="10" />
>>>>>>> </td>
>>>>>>>
>>>>>>> Pretty straightforward, or so you'd think! The problem is that I
>>>>>>>               
>>> get a
>>>       
>>>>>>> Class
>>>>>>> Cast Exception when I run the application
>>>>>>>
>>>>>>>               
>>>>>>>>> java.lang.ClassCastException
>>>>>>>>> java.lang.String
>>>>>>>>>                   
>>>>>>> in Tapestry and I enter data into this textfield and submit the
>>>>>>>               
>>> form.
>>>       
>>>>> The
>>>>>           
>>>>>>> problem is that the validate method in Min Class (
>>>>>>> org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as
>>>>>>>               
>>> you
>>>       
>>>>> can
>>>>>           
>>>>>>> see it's trying to cast the contents of the received
>>>>>>> Object to an Number, the problem it that this Object Contains a
>>>>>>>               
>>>>> String,
>>>>>           
>>>>>>> well, we are using a TextField component after all?
>>>>>>>
>>>>>>> public void validate(IFormComponent field, ValidationMessages
>>>>>>>               
>>>>> messages,
>>>>>           
>>>>>>> Object object)
>>>>>>>             throws ValidatorException
>>>>>>>     {
>>>>>>>         Number value = (Number) object;
>>>>>>>
>>>>>>>         if (_min > value.doubleValue())
>>>>>>>             throw new ValidatorException(buildMessage(messages,
>>>>>>>               
>>>>> field),
>>>>>           
>>>>>>>                     ValidationConstraint.TOO_SMALL);
>>>>>>>     }
>>>>>>>
>>>>>>> Now I know that you can't cast from a String to a
>>>>>>> Number,Integer,BigDecimal
>>>>>>> etc, but it's an Object we're casting from. I
>>>>>>> know that it contains a string, but its a numeric string i.e"123", is
>>>>>>>               
>>>>> it
>>>>>           
>>>>>>> that the Min class is at fault here or is it something I'm
>>>>>>> doing wrong?
>>>>>>>
>>>>>>> If Jesse Kuhnert is reading this and has five minutes to deliver
>>>>>>>               
>>> the
>>>       
>>>>>>> answer
>>>>>>> to my question it would be much appreciated.
>>>>>>>
>>>>>>> Brian Long.
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>>             
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>>           
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>>       
>>     
>
>
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>   


Re: Minimum and Maximum Validators in 4.0

Posted by Howard Lewis Ship <hl...@gmail.com>.
At the root of this is that the value comes up as a string, and if you
don't tell Tapestry otherwise, it stays a string ... but needs to be a
Number for max and min validators.

The translator parameter controls this.  You want to use
"translator:int" (I believe, check the docs). This will convert int
property on the server side to a string, and vice-versa.

On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> I meant more like the sample given in the translator parameter here (
> http://jakarta.apache.org/tapestry/tapestry/ComponentReference/DatePicker.html
> ).
>
>
>
> On 2/17/06, Brian Long <br...@gmail.com> wrote:
> >
> > Jesse,
> >
> > do you mean like this?
> >
> > <input jwcid="dummyTextField@TextField" value="translator:ognl:amount"
> > validators="validators:min=15,max=5000" size="10" />
> >
> > Regards, Brian.
> >
> > On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > > Oh, try adding the translator: binding as well :)
> > >
> > > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > > >
> > > > Jesse,
> > > >
> > > > thanks for the quick reply, but I have bound the value to
> > > > "ognl:amount", which is a BigDecimal (a subclass of Number) used in my
> > > > java class? Is this a step to far for the Compiler/Tapestry framework,
> > > > because if what you say is true, this should have worked.
> > > >
> > > > Brian.
> > > >
> > > > On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > > > > You need to have you value binding for TextField be either a Numeric
> > > > object
> > > > > type or native numeric value.  That's just the way it is for
> > now...Won't
> > > > be
> > > > > in tap4.1...
> > > > >
> > > > >
> > > > > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > > > > >
> > > > > > Hi guys,
> > > > > >
> > > > > > I've spend this afternoon trying to get the minimum and maximum
> > > > validators
> > > > > > for Tapestry 4.0 to work without success.
> > > > > >
> > > > > > I have a TextField component with an associated FieldLabel
> > component
> > > > onto
> > > > > > which I attach the Min and Max validators :
> > > > > >
> > > > > > <td>
> > > > > > <label jwcid="@FieldLabel" field="component:dummyTextField"
> > > > displayName=
> > > > > > "DummyTextField">DummyTextField</label>
> > > > > > </td>
> > > > > > <td>
> > > > > > <input jwcid="dummyTextField@TextField" value="ognl:amount"
> > > > > > validators="validators:min=15,max=5000"
> > > > > > size="10" />
> > > > > > </td>
> > > > > >
> > > > > > Pretty straightforward, or so you'd think! The problem is that I
> > get a
> > > > > > Class
> > > > > > Cast Exception when I run the application
> > > > > >
> > > > > > >>java.lang.ClassCastException
> > > > > > >>java.lang.String
> > > > > >
> > > > > > in Tapestry and I enter data into this textfield and submit the
> > form.
> > > > The
> > > > > > problem is that the validate method in Min Class (
> > > > > > org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as
> > you
> > > > can
> > > > > > see it's trying to cast the contents of the received
> > > > > > Object to an Number, the problem it that this Object Contains a
> > > > String,
> > > > > > well, we are using a TextField component after all?
> > > > > >
> > > > > > public void validate(IFormComponent field, ValidationMessages
> > > > messages,
> > > > > > Object object)
> > > > > >             throws ValidatorException
> > > > > >     {
> > > > > >         Number value = (Number) object;
> > > > > >
> > > > > >         if (_min > value.doubleValue())
> > > > > >             throw new ValidatorException(buildMessage(messages,
> > > > field),
> > > > > >                     ValidationConstraint.TOO_SMALL);
> > > > > >     }
> > > > > >
> > > > > > Now I know that you can't cast from a String to a
> > > > > > Number,Integer,BigDecimal
> > > > > > etc, but it's an Object we're casting from. I
> > > > > > know that it contains a string, but its a numeric string i.e"123", is
> > > > it
> > > > > > that the Min class is at fault here or is it something I'm
> > > > > > doing wrong?
> > > > > >
> > > > > > If Jesse Kuhnert is reading this and has five minutes to deliver
> > the
> > > > > > answer
> > > > > > to my question it would be much appreciated.
> > > > > >
> > > > > > Brian Long.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>


--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Minimum and Maximum Validators in 4.0

Posted by Jesse Kuhnert <jk...@gmail.com>.
I meant more like the sample given in the translator parameter here (
http://jakarta.apache.org/tapestry/tapestry/ComponentReference/DatePicker.html
).



On 2/17/06, Brian Long <br...@gmail.com> wrote:
>
> Jesse,
>
> do you mean like this?
>
> <input jwcid="dummyTextField@TextField" value="translator:ognl:amount"
> validators="validators:min=15,max=5000" size="10" />
>
> Regards, Brian.
>
> On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > Oh, try adding the translator: binding as well :)
> >
> > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > >
> > > Jesse,
> > >
> > > thanks for the quick reply, but I have bound the value to
> > > "ognl:amount", which is a BigDecimal (a subclass of Number) used in my
> > > java class? Is this a step to far for the Compiler/Tapestry framework,
> > > because if what you say is true, this should have worked.
> > >
> > > Brian.
> > >
> > > On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > > > You need to have you value binding for TextField be either a Numeric
> > > object
> > > > type or native numeric value.  That's just the way it is for
> now...Won't
> > > be
> > > > in tap4.1...
> > > >
> > > >
> > > > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > > > >
> > > > > Hi guys,
> > > > >
> > > > > I've spend this afternoon trying to get the minimum and maximum
> > > validators
> > > > > for Tapestry 4.0 to work without success.
> > > > >
> > > > > I have a TextField component with an associated FieldLabel
> component
> > > onto
> > > > > which I attach the Min and Max validators :
> > > > >
> > > > > <td>
> > > > > <label jwcid="@FieldLabel" field="component:dummyTextField"
> > > displayName=
> > > > > "DummyTextField">DummyTextField</label>
> > > > > </td>
> > > > > <td>
> > > > > <input jwcid="dummyTextField@TextField" value="ognl:amount"
> > > > > validators="validators:min=15,max=5000"
> > > > > size="10" />
> > > > > </td>
> > > > >
> > > > > Pretty straightforward, or so you'd think! The problem is that I
> get a
> > > > > Class
> > > > > Cast Exception when I run the application
> > > > >
> > > > > >>java.lang.ClassCastException
> > > > > >>java.lang.String
> > > > >
> > > > > in Tapestry and I enter data into this textfield and submit the
> form.
> > > The
> > > > > problem is that the validate method in Min Class (
> > > > > org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as
> you
> > > can
> > > > > see it's trying to cast the contents of the received
> > > > > Object to an Number, the problem it that this Object Contains a
> > > String,
> > > > > well, we are using a TextField component after all?
> > > > >
> > > > > public void validate(IFormComponent field, ValidationMessages
> > > messages,
> > > > > Object object)
> > > > >             throws ValidatorException
> > > > >     {
> > > > >         Number value = (Number) object;
> > > > >
> > > > >         if (_min > value.doubleValue())
> > > > >             throw new ValidatorException(buildMessage(messages,
> > > field),
> > > > >                     ValidationConstraint.TOO_SMALL);
> > > > >     }
> > > > >
> > > > > Now I know that you can't cast from a String to a
> > > > > Number,Integer,BigDecimal
> > > > > etc, but it's an Object we're casting from. I
> > > > > know that it contains a string, but its a numeric string i.e"123", is
> > > it
> > > > > that the Min class is at fault here or is it something I'm
> > > > > doing wrong?
> > > > >
> > > > > If Jesse Kuhnert is reading this and has five minutes to deliver
> the
> > > > > answer
> > > > > to my question it would be much appreciated.
> > > > >
> > > > > Brian Long.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: Minimum and Maximum Validators in 4.0

Posted by Brian Long <br...@gmail.com>.
Jesse,

do you mean like this?

<input jwcid="dummyTextField@TextField" value="translator:ognl:amount"
validators="validators:min=15,max=5000" size="10" />

Regards, Brian.

On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> Oh, try adding the translator: binding as well :)
>
> On 2/17/06, Brian Long <br...@gmail.com> wrote:
> >
> > Jesse,
> >
> > thanks for the quick reply, but I have bound the value to
> > "ognl:amount", which is a BigDecimal (a subclass of Number) used in my
> > java class? Is this a step to far for the Compiler/Tapestry framework,
> > because if what you say is true, this should have worked.
> >
> > Brian.
> >
> > On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > > You need to have you value binding for TextField be either a Numeric
> > object
> > > type or native numeric value.  That's just the way it is for now...Won't
> > be
> > > in tap4.1...
> > >
> > >
> > > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > > >
> > > > Hi guys,
> > > >
> > > > I've spend this afternoon trying to get the minimum and maximum
> > validators
> > > > for Tapestry 4.0 to work without success.
> > > >
> > > > I have a TextField component with an associated FieldLabel component
> > onto
> > > > which I attach the Min and Max validators :
> > > >
> > > > <td>
> > > > <label jwcid="@FieldLabel" field="component:dummyTextField"
> > displayName=
> > > > "DummyTextField">DummyTextField</label>
> > > > </td>
> > > > <td>
> > > > <input jwcid="dummyTextField@TextField" value="ognl:amount"
> > > > validators="validators:min=15,max=5000"
> > > > size="10" />
> > > > </td>
> > > >
> > > > Pretty straightforward, or so you'd think! The problem is that I get a
> > > > Class
> > > > Cast Exception when I run the application
> > > >
> > > > >>java.lang.ClassCastException
> > > > >>java.lang.String
> > > >
> > > > in Tapestry and I enter data into this textfield and submit the form.
> > The
> > > > problem is that the validate method in Min Class (
> > > > org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you
> > can
> > > > see it's trying to cast the contents of the received
> > > > Object to an Number, the problem it that this Object Contains a
> > String,
> > > > well, we are using a TextField component after all?
> > > >
> > > > public void validate(IFormComponent field, ValidationMessages
> > messages,
> > > > Object object)
> > > >             throws ValidatorException
> > > >     {
> > > >         Number value = (Number) object;
> > > >
> > > >         if (_min > value.doubleValue())
> > > >             throw new ValidatorException(buildMessage(messages,
> > field),
> > > >                     ValidationConstraint.TOO_SMALL);
> > > >     }
> > > >
> > > > Now I know that you can't cast from a String to a
> > > > Number,Integer,BigDecimal
> > > > etc, but it's an Object we're casting from. I
> > > > know that it contains a string, but its a numeric string i.e "123", is
> > it
> > > > that the Min class is at fault here or is it something I'm
> > > > doing wrong?
> > > >
> > > > If Jesse Kuhnert is reading this and has five minutes to deliver the
> > > > answer
> > > > to my question it would be much appreciated.
> > > >
> > > > Brian Long.
> > > >
> > > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Minimum and Maximum Validators in 4.0

Posted by Jesse Kuhnert <jk...@gmail.com>.
Oh, try adding the translator: binding as well :)

On 2/17/06, Brian Long <br...@gmail.com> wrote:
>
> Jesse,
>
> thanks for the quick reply, but I have bound the value to
> "ognl:amount", which is a BigDecimal (a subclass of Number) used in my
> java class? Is this a step to far for the Compiler/Tapestry framework,
> because if what you say is true, this should have worked.
>
> Brian.
>
> On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > You need to have you value binding for TextField be either a Numeric
> object
> > type or native numeric value.  That's just the way it is for now...Won't
> be
> > in tap4.1...
> >
> >
> > On 2/17/06, Brian Long <br...@gmail.com> wrote:
> > >
> > > Hi guys,
> > >
> > > I've spend this afternoon trying to get the minimum and maximum
> validators
> > > for Tapestry 4.0 to work without success.
> > >
> > > I have a TextField component with an associated FieldLabel component
> onto
> > > which I attach the Min and Max validators :
> > >
> > > <td>
> > > <label jwcid="@FieldLabel" field="component:dummyTextField"
> displayName=
> > > "DummyTextField">DummyTextField</label>
> > > </td>
> > > <td>
> > > <input jwcid="dummyTextField@TextField" value="ognl:amount"
> > > validators="validators:min=15,max=5000"
> > > size="10" />
> > > </td>
> > >
> > > Pretty straightforward, or so you'd think! The problem is that I get a
> > > Class
> > > Cast Exception when I run the application
> > >
> > > >>java.lang.ClassCastException
> > > >>java.lang.String
> > >
> > > in Tapestry and I enter data into this textfield and submit the form.
> The
> > > problem is that the validate method in Min Class (
> > > org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you
> can
> > > see it's trying to cast the contents of the received
> > > Object to an Number, the problem it that this Object Contains a
> String,
> > > well, we are using a TextField component after all?
> > >
> > > public void validate(IFormComponent field, ValidationMessages
> messages,
> > > Object object)
> > >             throws ValidatorException
> > >     {
> > >         Number value = (Number) object;
> > >
> > >         if (_min > value.doubleValue())
> > >             throw new ValidatorException(buildMessage(messages,
> field),
> > >                     ValidationConstraint.TOO_SMALL);
> > >     }
> > >
> > > Now I know that you can't cast from a String to a
> > > Number,Integer,BigDecimal
> > > etc, but it's an Object we're casting from. I
> > > know that it contains a string, but its a numeric string i.e "123", is
> it
> > > that the Min class is at fault here or is it something I'm
> > > doing wrong?
> > >
> > > If Jesse Kuhnert is reading this and has five minutes to deliver the
> > > answer
> > > to my question it would be much appreciated.
> > >
> > > Brian Long.
> > >
> > >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: Minimum and Maximum Validators in 4.0

Posted by Brian Long <br...@gmail.com>.
Jesse,

thanks for the quick reply, but I have bound the value to
"ognl:amount", which is a BigDecimal (a subclass of Number) used in my
java class? Is this a step to far for the Compiler/Tapestry framework,
because if what you say is true, this should have worked.

Brian.

On 2/17/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> You need to have you value binding for TextField be either a Numeric object
> type or native numeric value.  That's just the way it is for now...Won't be
> in tap4.1...
>
>
> On 2/17/06, Brian Long <br...@gmail.com> wrote:
> >
> > Hi guys,
> >
> > I've spend this afternoon trying to get the minimum and maximum validators
> > for Tapestry 4.0 to work without success.
> >
> > I have a TextField component with an associated FieldLabel component onto
> > which I attach the Min and Max validators :
> >
> > <td>
> > <label jwcid="@FieldLabel" field="component:dummyTextField" displayName=
> > "DummyTextField">DummyTextField</label>
> > </td>
> > <td>
> > <input jwcid="dummyTextField@TextField" value="ognl:amount"
> > validators="validators:min=15,max=5000"
> > size="10" />
> > </td>
> >
> > Pretty straightforward, or so you'd think! The problem is that I get a
> > Class
> > Cast Exception when I run the application
> >
> > >>java.lang.ClassCastException
> > >>java.lang.String
> >
> > in Tapestry and I enter data into this textfield and submit the form. The
> > problem is that the validate method in Min Class (
> > org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you can
> > see it's trying to cast the contents of the received
> > Object to an Number, the problem it that this Object Contains a String,
> > well, we are using a TextField component after all?
> >
> > public void validate(IFormComponent field, ValidationMessages messages,
> > Object object)
> >             throws ValidatorException
> >     {
> >         Number value = (Number) object;
> >
> >         if (_min > value.doubleValue())
> >             throw new ValidatorException(buildMessage(messages, field),
> >                     ValidationConstraint.TOO_SMALL);
> >     }
> >
> > Now I know that you can't cast from a String to a
> > Number,Integer,BigDecimal
> > etc, but it's an Object we're casting from. I
> > know that it contains a string, but its a numeric string i.e "123", is it
> > that the Min class is at fault here or is it something I'm
> > doing wrong?
> >
> > If Jesse Kuhnert is reading this and has five minutes to deliver the
> > answer
> > to my question it would be much appreciated.
> >
> > Brian Long.
> >
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Minimum and Maximum Validators in 4.0

Posted by Jesse Kuhnert <jk...@gmail.com>.
You need to have you value binding for TextField be either a Numeric object
type or native numeric value.  That's just the way it is for now...Won't be
in tap4.1...


On 2/17/06, Brian Long <br...@gmail.com> wrote:
>
> Hi guys,
>
> I've spend this afternoon trying to get the minimum and maximum validators
> for Tapestry 4.0 to work without success.
>
> I have a TextField component with an associated FieldLabel component onto
> which I attach the Min and Max validators :
>
> <td>
> <label jwcid="@FieldLabel" field="component:dummyTextField" displayName=
> "DummyTextField">DummyTextField</label>
> </td>
> <td>
> <input jwcid="dummyTextField@TextField" value="ognl:amount"
> validators="validators:min=15,max=5000"
> size="10" />
> </td>
>
> Pretty straightforward, or so you'd think! The problem is that I get a
> Class
> Cast Exception when I run the application
>
> >>java.lang.ClassCastException
> >>java.lang.String
>
> in Tapestry and I enter data into this textfield and submit the form. The
> problem is that the validate method in Min Class (
> org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you can
> see it's trying to cast the contents of the received
> Object to an Number, the problem it that this Object Contains a String,
> well, we are using a TextField component after all?
>
> public void validate(IFormComponent field, ValidationMessages messages,
> Object object)
>             throws ValidatorException
>     {
>         Number value = (Number) object;
>
>         if (_min > value.doubleValue())
>             throw new ValidatorException(buildMessage(messages, field),
>                     ValidationConstraint.TOO_SMALL);
>     }
>
> Now I know that you can't cast from a String to a
> Number,Integer,BigDecimal
> etc, but it's an Object we're casting from. I
> know that it contains a string, but its a numeric string i.e "123", is it
> that the Min class is at fault here or is it something I'm
> doing wrong?
>
> If Jesse Kuhnert is reading this and has five minutes to deliver the
> answer
> to my question it would be much appreciated.
>
> Brian Long.
>
>