You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lyallex <ly...@gmail.com> on 2008/11/05 16:59:57 UTC
Handling Integer overflows
Hi
Please be aware that I understand completely WHY the following is
happening (Integer overflow)
This question is about how to handle it.
I have a form that has an input field
<s:textfield name="creditcount"/>
In my action I have the fiollowing field
public Integer creditcount;
If I enter the String "2147482647" (equivalent to Integer.MAX_VALUE)
then this is converted into the Integer 2147482647 as expected.
If I enter the String "4294967298" this is converted to the Integer 2
(Like I say, I understand why this is happening)
What I need to happen is that if the String contains a value that is
out of range I don't even want the creditcount field in the action to
be set.
I have written a custom validator but it appears that the value is set
on the action before this gets called.
Is there some way I can 'intercept' this String and ignore it (i.e
don't even set the action field) if it is going to cause an overflow.
Thanks
Lyallex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Handling Integer overflows
Posted by Lyallex <ly...@gmail.com>.
Perfect solution ... works exactly as required.
Thanks
Lyallex
2008/11/5 Dave Newton <ne...@yahoo.com>:
>
> That would probably need to be handled via a converter, not a validator.
>
> Dave
>
> --- On Wed, 11/5/08, Lyallex <ly...@gmail.com> wrote:
>
>> From: Lyallex <ly...@gmail.com>
>> Subject: Handling Integer overflows
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Wednesday, November 5, 2008, 10:59 AM
>> Hi
>>
>> Please be aware that I understand completely WHY the
>> following is
>> happening (Integer overflow)
>> This question is about how to handle it.
>>
>> I have a form that has an input field
>>
>> <s:textfield name="creditcount"/>
>>
>> In my action I have the fiollowing field
>>
>> public Integer creditcount;
>>
>> If I enter the String "2147482647" (equivalent to
>> Integer.MAX_VALUE)
>> then this is converted into the Integer 2147482647 as
>> expected.
>>
>> If I enter the String "4294967298" this is
>> converted to the Integer 2
>> (Like I say, I understand why this is happening)
>>
>> What I need to happen is that if the String contains a
>> value that is
>> out of range I don't even want the creditcount field in
>> the action to
>> be set.
>>
>> I have written a custom validator but it appears that the
>> value is set
>> on the action before this gets called.
>>
>> Is there some way I can 'intercept' this String and
>> ignore it (i.e
>> don't even set the action field) if it is going to
>> cause an overflow.
>>
>> Thanks
>> Lyallex
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Handling Integer overflows
Posted by Dave Newton <ne...@yahoo.com>.
That would probably need to be handled via a converter, not a validator.
Dave
--- On Wed, 11/5/08, Lyallex <ly...@gmail.com> wrote:
> From: Lyallex <ly...@gmail.com>
> Subject: Handling Integer overflows
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Wednesday, November 5, 2008, 10:59 AM
> Hi
>
> Please be aware that I understand completely WHY the
> following is
> happening (Integer overflow)
> This question is about how to handle it.
>
> I have a form that has an input field
>
> <s:textfield name="creditcount"/>
>
> In my action I have the fiollowing field
>
> public Integer creditcount;
>
> If I enter the String "2147482647" (equivalent to
> Integer.MAX_VALUE)
> then this is converted into the Integer 2147482647 as
> expected.
>
> If I enter the String "4294967298" this is
> converted to the Integer 2
> (Like I say, I understand why this is happening)
>
> What I need to happen is that if the String contains a
> value that is
> out of range I don't even want the creditcount field in
> the action to
> be set.
>
> I have written a custom validator but it appears that the
> value is set
> on the action before this gets called.
>
> Is there some way I can 'intercept' this String and
> ignore it (i.e
> don't even set the action field) if it is going to
> cause an overflow.
>
> Thanks
> Lyallex
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org