This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

validation in struts2

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1. When I try to validate the form parameters in struts2 for "required" validation, all the other messages that are associated with the field are also being displayed.For ex:
<field name="empid">
<field-validator type="required">
<message>Emp id is required</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[^\d*$]]></param>
<message>Employee ID should be a number</message>
</field-validator>
<field-validator type="regex">
<param name="expression">^[1-9]\d*$</param>
<message>Employee ID cannot begin with a zero</message>
</field-validator>
</field>

In the above case, empid is an integer, when I do not specify any id and submit the form,all the above messages are displayed.How do I avoid this.

2.I ahve used the following pattern in validation.xml file for password and confrm password matching:
<validator type="expression">
<param name="expression">
password eq password2
</param>
<message>Confirm password should be same as password.</message>
</validator>
But there is no effect when I submit the form with differenct passwords.

Also, tried to use the following in action class but in vain:
@FieldExpressionValidator(expression = "(password == password2)", fieldName = "password2", message = "Passwords must match.")
Could you someone help me for the above two scenarios.

Thanks in advance.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For 1, use Short Circuiting Validator.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic