Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Validation Struts2

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anybody an idea?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic