This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes html:errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:errors" Watch "html:errors" New topic
Author

html:errors

Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
I am trying to do a form validation.when i use <html:errors/> in my form i am getting the exception as java.lang.ClassCastException
org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:224)
messageresorces is as follows
errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the following error(s) before proceeding:<ul>
errors.footer=</ul><hr>
errors.prefix=<li>
errors.suffix=</li>

########################################
# Exercise01 index page strings
########################################
page.title=Form Validation
########################################
# Form validation strings
########################################
formpage.title=Please enter your details
prompt.customer.name=Name
prompt.customer.address=Address
prompt.customer.emailAddress=EmailAddress
button.save=Save
button.cancel=Cancel

error.cust.name.empty=First Name is Required
error.cust.address.empty=Address Required
error.cust.emailAdress.empty=Email Address Required
my form bean contains
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();

// name cannot be empty
if (name == null || name.trim().equals(""))
{
errors.add("name", new ActionError("error.cust.name.empty"));
}

// Address cannot be empty
if (address == null || address.trim().equals(""))
{
errors.add("address", new ActionError("error.cust.address.empty"));
}

return errors;
}
Please help me correct the error
Gaurav Chhabras
Ranch Hand

Joined: Sep 21, 2005
Posts: 126
it seems to be correct, can you please paste your code where you are using <html:errors/>, i mean your JSP code.
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
This is the jsp


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

<html:html locale="true">

<head>

<title><bean:message key="page.title"/></title>

<html:base/>

</head>

<body bgcolor="white">
<html:errors/>
<html:form action="/Address">


<table>
<tr>

<td align="center" colspan="2">
<font size="4"><bean:message key="formpage.title"/></font>
</tr>
<tr>
<td alig

n="right">
<bean:message key="prompt.customer.name"/>:
</td>
<td align="left">

<html:text property="name" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<td align="right">
<bean:message key="prompt.customer.address"/>:
</td>
<td align="left">

<html:text property="address" size="30" maxlength="30"/>
</td>
</tr>

<tr>
<td align="right">
<bean:message key="prompt.customer.emailAddress"/>:
</td>
<td align="left">

<html:text property="emailAddress" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit><bean:message key="button.save"/></html:submit>
</td>
<td align="left">
<html:cancel><bean:message key="button.cancel"/></html:cancel>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
i fixed the problem by changing the version from 1.1 to 1.2.8
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:errors
 
Similar Threads
struts validation
ActionErrors with html:errors tag not displaying errors :-(
problem validating form fields in ActionForm......
Validate() method of ActionForm
Validation method in lookup form