• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to check if field exist in validation.xml

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm shared a form across 3 differenct jsp pages. Some of the jsp pages do not have all the fields in the form displayed. However, the validation is displaying error messages for the form fields that do not exist on the jsp page.

How do tell the validation.xml to only validate fields that are display on a page?

Here's my validation.xml:

<formset>
<form name="LoginForm">
<field property="userName" depends="required, email">
<msg name="email" key="errors.invalid" />
<arg0 key="prompt.username" />
</field>
<field property="passWord" depends="required, minlength, maxlength,mask">
<arg0 key="prompt.password" />
<arg1 key="${var:minlength}" name="minlength" resource="false" />
<arg2 key="${var:maxlength}" name="maxlength" resource="false" />
<arg3 key="${var:mask}" name="mask" resource="false" />
<var>
<var-name>minlength</var-name>
<var-value>8</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$</var-value>
</var>
</field>
</form>
</formset>
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a hidden field that stores what page you come from, then use that to filter the validation.

Alternatively, don't use validation on the form, call a validation method in your action class.

Either is a bit clumsy but will get the job done. There may be other more elegant methods, though.
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a more elegant solution.
 
Craig Bayley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I'd suggest defining some custom validation rules.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you may do something like this -
In your struts-config.xml file, have different form bean names for the same form - one each for each page.


Now, using this form bean name, you may have your validations declared in validation.xml file.
 
Craig Bayley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cringed initially, but on further reflection I like it. Very elegant.
 
Create symphonies in seed and soil. For this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!