jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Validate() method of ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validate() method of ActionForm" Watch "Validate() method of ActionForm" New topic
Author

Validate() method of ActionForm

Manu Ramakrishnan
Greenhorn

Joined: Jun 07, 2003
Posts: 10
Can anybody please help ? I am using WebSphere 4.0 Application server.
I am using the validate() method for client side validation. I am getting redirected to the input Page after validation errors. But the Error Messages which are coded in ApplicationResoureces.properties not shown in the page
JSP PAGE
<%@ page language= "java" session="true" %>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/lib/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/lib/struts-validator.tld" prefix="validator" %>
<html>
<head>
<title></title>
</head>
<body bgcolor="#E2E2E2">
<html:errors/>
<font face="Trebuchet MS" size=1>
<html:form action="/change_password">
<br><br><h4><b>                        
            CHANGE AUTHENICATION PASSWORD</b></h4><br><br>
<html:hidden property="userId" value='<%=(String)session.getAttribute("userId")%>'/>
<table border="0" width="50%" height="127" cellspacing="1">
<tr>
<td width="50%" height="26" align="right">User</td>
<td width="50%" height="26" align="left">
<input type="text" name="userName" size="20" value='<%=(String)session.getAttribute("userName")%>' style="background-color: #C0C0C0" readonly="true">
</td>
</tr>
<tr>
<td width="50%" height="26" align="right">Old password</td>
<td width="50%" height="26" align="left">
<html assword property="oldpwd" size="12" maxlength="8"/>
</td>
</tr>
<tr>
<td width="50%" height="26" align="right">New password</td>
<td width="50%" height="26" align="left">
<html assword property="newpwd" size='12' maxlength='8'/>
</td>
</tr>
<tr>
<td width="50%" height="26" align="right">Re-type new password</td>
<td width="508%" height="26" align="left">
<html assword property="rnewpwd" size="12" maxlength="8"/>
</td>
</tr>
<tr>
<td colspan="2" height="26"align="center">
</td>
</tr>
<tr>
<td colspan="2" height="26" align="center">
<html:submit property = "change" value="Change Password"/>
<html:reset value="Reset"/>
</td>
</table>
</font>

</html:form>
</body>
</html>
Validate method
public ActionErrors validate(ActionMapping amapping, HttpServletRequest request)
{
ActionErrors errors=new ActionErrors();
if ((oldpwd==null) || (oldpwd.length() != 8))
errors.add("oldpwd", new ActionError("error.changepwd.oldpwd"));
if ((newpwd==null) || (newpwd.length() != 8))
errors.add("newpwd", new ActionError("error.changepwd.newpwd"));
if ((rnewpwd==null) || (rnewpwd.length() != 8))
errors.add("rnewpwd", new ActionError("error.changepwd.rnewpwd"));
if (!newpwd.equals(rnewpwd))
errors.add("notmatch", new ActionError("error.changepwd.notmatch"));
return errors;
}
ApplicationResources.properties
errors.header=<h3>Errors :</h3><UL>
errors.footer=</UL><hr>
error.changepwd.oldpwd=<li>Old password length is invalid</li>
error.changepwd.newpwd=<li>New password length is invalid</li>
error.changepwd.rnewpwd=<li>Retyped new password length is invalid</li>
error.changepwd.notmatch=<li>New password and Re-typed new password do not match</li>
[ July 02, 2003: Message edited by: Manu Ramakrishnan ]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
First thing for your info, this is a server side validation. Client side validation can only be done via Javascript.
To show your error messages add the following code to your page,e.g.
<html:errors property="changepwd.oldpwd"/>
On this location the error message now appears
Olli
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate() method of ActionForm
 
Similar Threads
<html:error> tag doubt in struts 1
Problem in SessionManagement in Struts
Struts: No getter method for property name problem
Cannot retrieve mapping for action
&gt;html:text &lt; default value