| 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.
|
 |
 |
|
|
subject: HTML:Errors and Validate woes
|
|
|