Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Form - ERROR_KEY & saveErrors

 
satish pune
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please explain the significance of thie variable
" ERROR_KEY " in the Struts Action class ?
How can I make use of it ?
Also I was wondering what the use of the method "saveErrors" is ?
Do I need to implement this method in my action class ?
Thanks in advance ,
-satish
[ September 05, 2003: Message edited by: satish pune ]
[ September 05, 2003: Message edited by: satish pune ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by satish pune:
Could someone please explain the significance of thie variable
" ERROR_KEY " in the Struts Action class ?
How can I make use of it ?
Also I was wondering what the use of the method "saveErrors" is ?
Do I need to implement this method in my action class ?
Thanks in advance ,
-satish

This is my understanding,
Even though you have created the ActionErrors instance and populated it with ActionError objects, it needs to be available in the request for later retreival. This is what saveErrors(request,errors) does, it stores the errors in the http request object under the key Globals.ERROR_KEY.
You dont have to implement it since org.apache.struts.action.Action from which your Action class extends already does it.
If you do request.getAttribute(Globals.ERROR_KEY) in the resource you have forwarded to, you s'd be able to get an ActionErrors instance if an error had actually occured and you had stored it in the request object.
If you are forwarding to a JSP, you dont have to make use of Globals.ERROR_KEY, use html:errors tag instead. By default it looks up the request using the Globals.ERROR_KEY key.
Am not sure how to store the errors under a differnt key though. :roll:
Yes you can defintely do a request.setAttribute("some-other-error-key",errors) in your action class. I dont know how to make saveErrors() store the errors under a different key though.

If am wrong please somebody correct me.
 
satish pune
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks karthik
that was helpful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic