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

use of requiredIf in validation.xml

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
The condition is :I have two groups of radio button.
sex : Male & Female
Agegroup : 18-30 & 30 Above
On clicking on the diffrent radio button different sets of textbox displayed through JS.
Now I want to use validator :requiredIf or ValidWhen whatever it may be to ascertain that mandatory field for different set of radio button chosen must be filled.
Can anyone please help me with the code of validation.xml
Condition:Say when Sex Male & agegroup 18-30 selected Hobbies field must be given.
 
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't this be in the struts forum. Anyway, requiredIf is deprecated and you should use validWhen instead. Anyway, whether you use this or that, you have to define a variable called test, where you put you boolean expression. For example, if you use validWhen in your case, it should look something like this:



Which means that this field is valid when sex is not M or the age group is not the first one or the hobbies is not null. This means that if the user chooses both M and the first age group, then he MUST fill the hobbies field, or it won't be valid. You can build much more complex scenarios if you want.

As for requiredIf (which is deprecated as I stated before), you also define the test variable, and it will mean that this field is required if the following test succeeds. As you can see, validWhen is much better.
 
Suddhasattwa Mukherjee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply...
But this code is not working for me.I have tried view source of that page and there is no validateValidWhen method created as for required and mask-it is created.I am using Struts 1.2.7 and also there is validwhen validator in validation-rules.xml files.
what would be the cause for this can you please suggest?
 
Alaa Nassef
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. You should take this to the struts forum. You'll get more help there
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic