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 and Validate woes 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 and Validate woes" Watch "HTML:Errors and Validate woes" New topic
Author

HTML:Errors and Validate woes

Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
I can't seem to get errors.add to work for me inside of validate.
Here's a quick snippet of my code:

Thanks to my fancy debugging, it appears that I am blowing up at the return errors line. I get a lovely stack dump, starting with this message:
E SRVE0026E: [Servlet Error]-[org.apache.struts.action.ActionMessage]: java.lang.ClassCastException: org.apache.struts.action.ActionMessage

I have my ApplicationResources.properties file, and as far as I can tell it's set up correctly, and is in the right place.

What am I doing wrong?

Thanks
Andrew
Ramon Talavera
Greenhorn

Joined: Nov 08, 2005
Posts: 2
Same error for me, Andrew.

[8/11/05 17:38:01:671 CET] 1ca22de WebGroup E SRVE0026E: [Error de servlet]-[org.apache.struts.action.ActionMessage]: java.lang.ClassCastException: org.apache.struts.action.ActionMessage

But I am filling the errors with ActionMessages correctly!
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();

if (getNombre().trim().equals(""))
{
ActionMessage msg=new ActionMessage("errors.required","Nombre");
errors.add("msg1",msg);
}
return (errors);
}

What are we doing wrong? in fact it crashes when trying to decode the error at the <html:errors/> line.

Please help.
Ramon Talavera
Greenhorn

Joined: Nov 08, 2005
Posts: 2
Hello again.
After testing a bit, I managed to make it work, have you set up your properties files correctly?

Have in mind that the message has to be correctly placed in the properties file.

resources:
my.properties
# -- my errors --
error.notallowed=No permitido.

struts-config.xml:
<message-resources parameter="resources.my" />

code:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();

if (getNombre().trim().equals("none"))
{

errors.add("form errors",new ActionError("error.notallowed"));


}
return (errors);
}

Worked after a server relaunch. It seems to me that you are working under Websphere, right?

Regards,
R.Talavera
lubomir karaba
Greenhorn

Joined: Nov 11, 2005
Posts: 1
main change is:

ActionMessage error = new ActionMessage("errors.required", "Login Name");

to

ActionError error = new ActionError("errors.required", "Login Name");
Dave McLoughlin
Greenhorn

Joined: Jun 02, 2006
Posts: 1
ActionError is now deprecated. I had this same ClassCastException when adding an ActionMessage object to my ActionErrors object.

However, when i re-checked i found that the properties i had set in my resource file were slightly wrong.

Therefore ActionMessage will work exactly the same as ActionError as long as you have your properties file set up correctly.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HTML:Errors and Validate woes
 
Similar Threads
how to use html:errors
validating file uploads
Error object is not caught by the Controller
Validation not working - any ideas
validation error causes an URL problem!!