hi,
I plan to use the
struts validator for client & server side validations. I dont have much knowledge in validator, but i coded as per sample code and tutorial examples that i found on the web. But it doesnt seem to work. when i hit the submit key, the page reloads without any error messages. the execute method in my action is also being called. for eg in the below pasted code, the userid & password fields are "required". so if nothing is entered, it should display an err message & not go through the execute method. here are the steps i followed:
1. uncommented the plug-in tag in struts-config as:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
2. form bean and action declaration:
<form-bean name="loginForm" type="form.LoginForm" />
...
<action path="/LoginAdmin" type="action.SigninAction"
name="loginForm"
parameter="methodToCall"
scope="request"
input="/pages/AdminLogin.jsp"
validate="true">
<forward name="success" path="/pages/Homepage.jsp" />
<forward name="failure" path="/pages/AdminLogin.jsp" />
</action>
3. in my validation.xml file:
...
<form name="loginForm">
<field property="userid" depends="required">
<arg0 key="loginForm.userid"/>
</field>
<field property="password" depends="required">
<arg0 key="loginForm.password"/>
</field>
</form>
4. in message resources :
errors.required={0} is a mandatory field. Please enter a value.
loginForm.userid=User ID
loginForm.password=Password
5. in validation-rules.xml file :
...
<validator name="required"
classname="org.apache.struts.util.StrutsValidator"
method="validateRequired"
methodparams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>
6. the form bean LoginForm extends ValidatorForm. action does not contain a validate method.
7.
JSP file:
<html:errors/>
<html:form method="post" action="/LoginAdmin?methodToCall=login"
onsubmit="return validateloginForm(this);">
<table border=0 width="100%">
<tr><td>User Id:</td><td><html:text property="userid"/></td></tr>
<tr><td>Password:</td><td><html:password
property="password"/></td></tr>
<tr><td><html:submit property="submit" value="Login" /></td></tr>
</table>
</html:form>
Please advice. any help is appreciated.