Home Answers Viewqa Struts What is Struts 2 RequiredFieldValidator? Need an Example or Code

 
 


meeya
What is Struts 2 RequiredFieldValidator? Need an Example or Code
2 Answer(s)      5 years and 3 months ago
Posted in : Struts

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.