• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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".
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic