• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

ActionErrors (Struts)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Jakarta Struts: I am trying to display errors that occur in my Action classes in a jsp page. I though I could just create an ActionErrors collection and forward the action to a jsp and display the errors using the tag <html:errors>. However, it appears that this only works for ActionForms (via the validate method). Is there a way to display errors that occur in the Action class or do I have to create my own custom tag? Thank for the help!
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your action, are you calling saveErrors?
For example:
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I cover that in my article:
http://www.javaranch.com/newsletter/Mar2002/newslettermar2002.jsp#struts
 
dawn cal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Thomas, that is a great article. However, it explains how to use ActionErrors with the validate method of the ActionForm. I don't have a form associated with this particular action.
I do use saveErrors() to save the errors to the request. I am just having trouble displaying them. The tag <html:errors/> displays the error.header and error.footer but not the error messages. I tried checking for errors in the jsp page:
ActionErrors ae = (ActionErrors) request.getAttribute(Action.ERROR_KEY);
if(ae != null){
out.println("There are errors!!");

for(int x=0; x<ae.size(); x++){
out.println(ae.get(ae.GLOBAL_ERROR));
}
}
But this is what is printed to the page:
java.util.AbstractList$Itr@e7d503 java.util.AbstractList$Itr@51dcd6
Thanks for your help!
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as you are adding ActionError objects to the ActionErrors collection correctly and using saveErrors(), then <html:errors/> should work. Can you show us what code you use in your action to instantiate the relevant objects (ActioneErrors and ActionError objects), add them to the collection, and save them?
Please use the UBB CODE tag for readability when you post code, thanks.
[ August 26, 2002: Message edited by: Jason Menard ]
 
dawn cal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I do in the perform method of my Action class.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess we can assume that your errors object is not empty and the conditional clause is being executed. You said it displays the header and footer, so that tells me that the taglib is being imported and that ApplicationResources.properties is correctly definied in your web.mxl.
Are you certain that "error.task.notassigned" is definied in your ApplicationResources.properties? Other than that possibility, everything looks correct and I can't see any problems.
 
dawn cal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right Jason... I didn't have my error message defined in my properties file. I am such a dummy. Thank you so much for all your help!!
Ahhhhhhhhhhh!!!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Struts higher versions (above 1.2.0 i guess ), the usage of ActionError is depricated, hence the following code will help to resolve it if you want ,

Use your code similar to the following in your action class to add the action errors,

ActionErrors errors = null;
errors = (ActionErrors) request.getAttribute(Globals.ERROR_KEY);
if (errors == null) {
errors = new ActionErrors();
}
errors.add("Global Error message", new ActionMessage("error.provided.in propertiesfile"));
request.setAttribute(Globals.ERROR_KEY, errors);

 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic