validating integer, java.lang.NoSuchMethodException

2010-07-12 Thread Jake Vang
hi,

i am trying to validate an integer field (int primitive type) on a
POJO (i.e. MyPojo.integer). i have the validation defined in
--validation.xml as follows.

...

 
  Integer is required!
 

...

when the form posts to the action, if the value of  is left blank, i keep seeing a
java.lang.NoSuchMethodException:
MyPojo.setInteger([Ljava.lang.String;). why is struts trying to insert
a string into this int field?  the field value is "blank" (empty), so
i'd expect struts to be smart enough to see this and not try to insert
anything and just return back to the form with the validation error.

it should be very easy to define the following validation rules:
1. myPojo.integer is required
2. myPojo.integer is an integer

however, it is NOT that easy. here's a set of validation rules that i
tried and did not succeed.


 
 
  Integer is required!
 
 
 
  
  Please enter an integer!
 


when i use this set of validation rules, i also observe the same
NoSuchMethodException. this time, however, i do NOT see that the
validation works (because I do not see the message, Integer is
required!).

something like the following works, but STILL, i see the
NoSuchMethodException thrown if the field's value is left blank.
...

 1
 10
 Integer must be between ${min} and ${max}, current value is
${myPojo.integer}.

...

however, this last validation rule is absolutely the WORST one to use
because if the value on the form is left blank, 1) i will see the
NoSuchMethoException thrown and 2) if i allow for min=0 and max=10,
the validation will never know if the user entered 0 or was the 0
because there was no value!

any ideas is appreciated. i already experimented a lot and did not
come up with anything that is why this post is rather long.

thanks.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: validating integer, java.lang.NoSuchMethodException

2010-07-12 Thread Jake Vang
a workaround to this problem is to have a string field in the Action
class to represent MyPojo.integer. using this approach, the second set
of validation rules below work 100% and i no longer see the
NoSuchMethodException. however, the drawback is that now i have to
transfer this to my backing bean.

oh well, you win some, you lose some. if anyone has a better idea,
please let me know.

thanks.

On Mon, Jul 12, 2010 at 11:26 AM, Jake Vang  wrote:
> hi,
>
> i am trying to validate an integer field (int primitive type) on a
> POJO (i.e. MyPojo.integer). i have the validation defined in
> --validation.xml as follows.
>
> ...
> 
>  
>  Integer is required!
>  
> 
> ...
>
> when the form posts to the action, if the value of  name="myPojo.integer"/> is left blank, i keep seeing a
> java.lang.NoSuchMethodException:
> MyPojo.setInteger([Ljava.lang.String;). why is struts trying to insert
> a string into this int field?  the field value is "blank" (empty), so
> i'd expect struts to be smart enough to see this and not try to insert
> anything and just return back to the form with the validation error.
>
> it should be very easy to define the following validation rules:
> 1. myPojo.integer is required
> 2. myPojo.integer is an integer
>
> however, it is NOT that easy. here's a set of validation rules that i
> tried and did not succeed.
>
> 
>  
>  
>  Integer is required!
>  
>  
>  
>  
>  Please enter an integer!
>  
> 
>
> when i use this set of validation rules, i also observe the same
> NoSuchMethodException. this time, however, i do NOT see that the
> validation works (because I do not see the message, Integer is
> required!).
>
> something like the following works, but STILL, i see the
> NoSuchMethodException thrown if the field's value is left blank.
> ...
> 
>  1
>  10
>  Integer must be between ${min} and ${max}, current value is
> ${myPojo.integer}.
> 
> ...
>
> however, this last validation rule is absolutely the WORST one to use
> because if the value on the form is left blank, 1) i will see the
> NoSuchMethoException thrown and 2) if i allow for min=0 and max=10,
> the validation will never know if the user entered 0 or was the 0
> because there was no value!
>
> any ideas is appreciated. i already experimented a lot and did not
> come up with anything that is why this post is rather long.
>
> thanks.
>

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org