• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

returning errors to client page

 
Greenhorn
Posts: 6
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which the correct way of returning the error to the client page?

method I
---------
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.exception.occured"));
saveErrors(request, errors);

if(!errors.isEmpty()){
return mapping.getInputForward();
}

method II
----------

errors.add(userdefinedstaticclass.constantvalue, new ActionError("error.exception.occured"));
request.setattribute(userdefinedstaticclass.constantvalue,errors)

fetching the error from client page to which the transition is set.

pls help

regards
mathi
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a mixture of both

errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.exception.occured"));
request.setattribute(userdefinedstaticclass.constantvalue,errors);

if(!errors.isEmpty()){
return mapping.getInputForward();
}
 
Author
Posts: 93
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mathivanan,

Are you trying to redirect the user with an error from within the execute() method of an Action class? If you are doing this method one looks fine. When you redirect the user to the page via the forward the <html:errors> tag will check to see if an ActionErrors collection (properly keyed in the request or session of course) is present. If the ActionErrors collection is present, it will render the error output.

If you are trying to add an error from a validate() method, you can just create an ActionErrors collection, add the Action error and return it. Struts will automatically redirect you back to the JSP page it came from if it an ActionErrors collection is returned of size < 0.

Please let me know if that does not answer the question.

Thanks,
John
 
Mathivanan Pandurangan
Greenhorn
Posts: 6
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much John... the answer was very clear and helpful
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!