This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation Struts2

 
Anonyhm Poulette
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anybody an idea?
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonyhm Poulette
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic