Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Struts%20Interview%20Questions%20and%20Answers

Question: Can you give me a simple example of using the requiredif Validator rule?
Answer: First off, there's an even newer Validator rule called
validwhen, which is almost certainly what you want to use,
since it is much easier and more powerful.
It will be available in the first release after 1.1 ships.
The example shown below could be coded with validwhen as:



property="pregnancyTest" depends="validwhen">


test
((((sex == 'm') OR (sex == 'M'))
AND (*this* == null)) OR (*this* != null))



Let's assume you have a medical information form
with three fields,
sex, pregnancyTest, and testResult. If sex is 'f' or 'F',
pregnancyTest is required. If pregnancyTest is not blank,
testResult is required. The entry in your validation.xml
file would look like this:



property="pregnancyTest" depends="requiredif">


field[0]
sex


fieldTest[0]
EQUAL


fieldValue[0]
F


field[1]
sex


fieldTest[1]
EQUAL


fieldValue[1]
f


fieldJoin
OR



property="testResult" depends="requiredif">


field[0]
pregnancyTest


fieldTest[0]
NOTNULL


Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook