| Author |
Validation Struts2
|
Anonyhm Poulette
Greenhorn
Joined: Apr 11, 2011
Posts: 3
|
|
Hi,
First, sorry for my bad English.
I have a form which contains a field named "duree" which must be a float and required.
I have in my file ObjetAction-ObjetAction_saveObjet-validation.xml :
The validation of the field's type is made automatically.
But when I enter a String for example, the message "duree is required" appears too.
How can I do to short-circuit this message when the type of field isn't correct?
Thanks you in advance for your answers.
|
 |
Anonyhm Poulette
Greenhorn
Joined: Apr 11, 2011
Posts: 3
|
|
|
Has anybody an idea?
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8290
|
|
Anonyhm Poulette wrote:
The validation of the field's type is made automatically.
I don't think so. I seem to remember a fair bit of trouble with number validation, like blank strings fail silently (due to type conversion), and the number validators check a range but don't check that the conversion is correct.
The solution in the linked topic appears to be to use a required String validator and a regex validator.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Anonyhm Poulette
Greenhorn
Joined: Apr 11, 2011
Posts: 3
|
|
First, thank you for your answer!
Secondly, I have in my jsp :
Since I use the tag <s:fielderror>, Struts 2 checks that what you enter in the field is of the same type as the attribute in the action.
In my action, the attribute "duree" is a BigDecimal.
So, if I enter "yyy" for example in my field "duree", the message "invalid field value" appears even if I haven't a field-validator in my xml file.
It's why I say that the validation of the field's type is made automatically.
My problem is when I enter an invalid value, my attribute stays "null" and also, the message "duree is required" appears too, and I wish have only
the message "invalid field value".
|
 |
 |
|
|
subject: Validation Struts2
|
|
|