You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Lindholm <gr...@gmail.com> on 2009/12/04 16:04:47 UTC

Re: RequiredFieldValidator and error message from property file via key

You may have a different problem then you think;

The @RequiredFieldValidator does not make any sense on a int
(primitive) field as an int cannot be null. The validation interceptor
checks the values on the fields after params interceptor sets the
fields. The RequiredFieldValidator checks if the field is null which
will never be the case for a primitive field.


On Fri, Dec 4, 2009 at 5:25 AM, Per Johansson <pe...@gmail.com> wrote:
> Hi,
>
> I'm trying to get error messages from a resource bundle.
>
> This is the code for my action class:
>
> @RequiredFieldValidator(type=ValidatorType.FIELD,
> key="myFieldErrorMsg", message="Error!!!!")
> public void setMyField(int myField) {
>    this.myField = myField;
> }
>
> @Override
> public void validate() {
>    if (!isMyFieldValid(myField)) {
>        addFieldError("myField", getText("myFieldErrorMsg"));
>    }
> }
>
> When validation fails for setMyField I don't get the expected error
> message from my resource bundle.
> Instead I get a struts default error message "Invalid field value for field ..."
>
> But when i call getText from the validate method, I get the expected
> error message.
>
> How can I get a message from a resource bundle using the annotation
> based validator?
> I'm using weblogic 10.0.
>
>
> /Best regards, Per Johansson
>
> ---------------------------------------------------------------------
> 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: RequiredFieldValidator and error message from property file via key

Posted by nguyenlinh <ng...@gmail.com>.
I found the @ConversionErrorFieldValidator and it works almost the way I
wanted.
Now I get my error message but I also get the default struts error message
which is: Invalid field value for field "<field-name>".
Is there any "simple" way I can get rid of the default message from struts?
Thanks


nguyenlinh wrote:
> 
> Hello,
> I have the same problem. So what kind of validator should I use if I have
> a field of type int and I want to make sure the user typed a number?
> Thanks,
> Linh
> 
> 
> Greg Lindholm-2 wrote:
>> 
>> You may have a different problem then you think;
>> 
>> The @RequiredFieldValidator does not make any sense on a int
>> (primitive) field as an int cannot be null. The validation interceptor
>> checks the values on the fields after params interceptor sets the
>> fields. The RequiredFieldValidator checks if the field is null which
>> will never be the case for a primitive field.
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RequiredFieldValidator-and-error-message-from-property-file-via-key-tp26640581p26669331.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: RequiredFieldValidator and error message from property file via key

Posted by nguyenlinh <ng...@gmail.com>.
Hello,
I have the same problem. So what kind of validator should I use if I have a
field of type int and I want to make sure the user typed a number?
Thanks,
Linh


Greg Lindholm-2 wrote:
> 
> You may have a different problem then you think;
> 
> The @RequiredFieldValidator does not make any sense on a int
> (primitive) field as an int cannot be null. The validation interceptor
> checks the values on the fields after params interceptor sets the
> fields. The RequiredFieldValidator checks if the field is null which
> will never be the case for a primitive field.
> 
> 

-- 
View this message in context: http://old.nabble.com/RequiredFieldValidator-and-error-message-from-property-file-via-key-tp26640581p26669216.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: RequiredFieldValidator and error message from property file via key

Posted by nguyenlinh <ng...@gmail.com>.
I found the solution now.
Just override invalid.fieldvalue.<field-name> in your properties file.
for example:

invalid.fieldvalue.aField=Ivalid value for "aField".

Thanks a lot, your answer got me on the right track.


Greg Lindholm-2 wrote:
> 
> You may have a different problem then you think;
> 
> The @RequiredFieldValidator does not make any sense on a int
> (primitive) field as an int cannot be null. The validation interceptor
> checks the values on the fields after params interceptor sets the
> fields. The RequiredFieldValidator checks if the field is null which
> will never be the case for a primitive field.
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RequiredFieldValidator-and-error-message-from-property-file-via-key-tp26640581p26669544.html
Sent from the Struts - User mailing list archive at Nabble.com.


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