• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to check if field exist in validation.xml

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need a more elegant solution.
 
Craig Bayley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then I'd suggest defining some custom validation rules.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cringed initially, but on further reflection I like it. Very elegant.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic