|
Technical Interview Questions
Oracle Interview Questions
J2EE Interview Questions
C++
Interview Questions
XML
Interview Questions
EJB
Interview Questions
JSP
Interview Questions
.........More
Programming Source Codes
Java Source Codes
Html Source Codes
CSS Source Codes
C Source Codes
.........More
Soft Skills
Communication Skills
Leadership Skills
.........More
|
|
Structs Interview Questions and Answers
Can you give me a simple example of using
the requiredif Validator rule?
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:
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="validwhen">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>test</var-name>
<var-value>((((sex == 'm') OR (sex == 'M'))
AND (*this* == null)) OR (*this* != null))</test>
</var>
</field>
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:
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="requiredif">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[0]</var-name>
<var-value>F</var-value>
</var>
<var>
<var-name>field[1]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[1]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[1]</var-name>
<var-value>f</var-value>
</var>
<var>
<var-name>fieldJoin</var-name>
<var-value>OR</var-value>
</var>
</field>
<field
property="testResult" depends="requiredif">
<arg0 key="medicalStatusForm.testResult.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>pregnancyTest</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>NOTNULL</var-value>
</var>
</field>
</form>
When is the best time to validate input?
This is an excellent question. Let's step back a second and think about
a typical mid to large size application. If we start from the back end
and work toward the view we have:
1) Database: Most modern databases are going to validate for required
fields, duplicate records, security constraints, etc.
2) Business Logic: Here you are going to check for valid data
relationships and things that make sense for the particular problem you
are triing to solve.
... This is where struts comes into the picture, by now the system
should be pretty well bulletproof. What we are going to do is make
validation friendlier and informative. Rember it is OK to have duplicate
validations...
3) ActionErrors validate(ActionMapping map, HttpServletRequest req) is
where you can do your validation and feed back to the view, information
required to correct any errors. validate is run after the form has been
reset and after the ActionForm properties have been set from
corresponding view based input. Also remember you can turn validation
off with validate="false" in the action mapping in the struts-config.xml.
This is done by returning an ActionErrors collection with messages from
your ApplicationResources.properties file.
Here you have access to the request so you can see what kinds of action
is being requested to fine tune your validations. The <html:error> tag
allows you to dump all errors on your page or a particular error
associated with a particular property. The input attribute of the
struts-config.xml action allows you to send validation errors to a
particular jsp / html / tile page.
4) You can have the system perform low level validations and client side
feedback using a ValidatorForm or its derivatives. This will generate
javascript and give instant feedback to the user for simple data entry
errors. You code your validations in the validator-rules.xml file. A
working knowledge of regular expressions is necessary to use this
feature effectively.
Page Numbers
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Java Interview
Questions for more Java Interview Questions with answers
Check
Servlet Interview
Questions for more Servlet Interview Questions with answers
|