What is Struts 2 RequiredFieldValidator? Need an Example or Code

What is Struts 2 RequiredFieldValidator? Need an Example or Code

What is Struts 2 RequiredFieldValidator?
Need an Example or Code on Field Validation in Struts 2.

View Answers

February 21, 2008 at 8:06 PM

Please follow the following instruction:

1. index.jsp

<ul>
<li><a href="roseindia/requiredFieldValidatorError.action">RequiredFieldValidator Example</a></li>
</ul>

2. struts.xml

<action name="requiredFieldValidatorError">
<result>/pages/chatQuestion/requiredFieldValidatorError.jsp</result>
</action>

<action name="requiredFieldValidatorError1" class="net.roseindia.requiredFieldValidatorAction">
<result name="input">/pages/chatQuestion/requiredFieldValidatorError.jsp</result>
<result name="error">/pages/chatQuestion/requiredFieldValidatorError.jsp</result>
<result name="success">/pages/chatQuestion/requiredFieldValidatorSuccess.jsp</result>
</action>

3. requiredFieldValidatorError.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title>RequiredFieldValidator Example!</title>

<link href="<s:url value="/css/main.css"/>" rel="stylesheet"
type="text/css"/>

<s:head theme="ajax" />
<s:actionerror/>

</head>
<body>

<s:form name="validate" action="requiredFieldValidatorError1" method="POST" validate="true">
<s:textfield name="username" label="Username"/>
<s:password name="password" label="Password"/>
<s:submit value="Submit" />

</s:form>

</body>

</html>

4. requiredFieldValidatorSuccess.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title>RequiredFieldValidator Example!</title>

<link href="<s:url value="/css/main.css"/>" rel="stylesheet"
type="text/css"/>
</head>
<body>

Username: <s:property value="username" /><br>
Password: <s:property value="password" />

</body>

</html>

Whenever user don't input any data then it displays an error. If you enter username and password then you get your username and password in requiredFieldValidatorSuccess.jsp.

February 21, 2008 at 8:19 PM

For knowing more information about RequiredFieldValidator then you go:http://www.roseindia.net/struts/struts2/struts2login.shtml

Regards
Neelam









Related Tutorials/Questions & Answers:
What is Struts 2 framework
Need an example of basic code.
Advertisements
Need an example of basic code.
Need an example of basic code.
Struts 2 zero configuration,Struts 2 zero configuration Example
Need help to create Struts 2 MySQL based HRMS application.
Struts 2 Login Form Example
Struts 2 Hello World Example
Struts: validations code to support 2 date foramats - Struts
What are Interceptors in Struts 2 and how do they work?
Struts 2 Validation Example
need pyspark lit function example code
Struts 2 datetimepicker Example
Please explain what is hibernatetemplate with an example code.
Struts 2 - Validation - Struts
Struts 2
Struts 2 RequiredFieldValidator - Struts
Struts 2
Struts 2
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
example on struts - Struts
what are Struts ?
struts 2 testing
need help for writting code in struts action class for check boxes and radio buttons - Struts
Struts 2 Tutorials - Struts version 2.3.15.1
struts 2 tabbedpanel - Struts
What is struts - Struts
Struts 2 Hello World Annotation Example
Struts 2 File Upload
Struts 2 Date Format Examples
Struts 2 Guide
Pagination in struts 2
Struts 2 Video Tutorial
Struts 2 problem - Struts
need dynamic image example
struts 2 mysql
Struts 2 Tutorial and Examples
What are Struts?
Struts 2 + hibernate
need of code
Integrating Struts 2 with hybernate - Struts
need code
need code
need code
Struts 2 Interceptor Example
Struts 2 - Beganner
Struts 2 Integration with Struts 1
Need acode for struts implementation - Struts
Time Picker in struts 2 - Struts
Struts 2 + Ajax

Ads