struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <greg.lindh...@gmail.com>
Subject Re: RequiredFieldValidator and error message from property file via key
Date Fri, 04 Dec 2009 15:04:47 GMT
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 <perjoha@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


Mime
View raw message