Subject: Difference between addErrors() and saveErrors()
Posted By: tilakkalyan Post Date: 1/18/2006 7:27:45 AM
What is the difference between addErrors() and saveErrors() in Action class of struts framework ?

M Kalyan Tilak
Reply By: kishore.dyn Reply Date: 2/15/2006 2:04:46 AM
hello sir this ram kishore (vrc)my mail ID is:krkfriends@gmail.com

k.ram kishore
Reply By: longjava Reply Date: 2/15/2006 2:02:45 PM
They are pretty much doing the same thing by adding the error messages to the container object(ActionMessages), and store the container object to the request's attribute name Globals.ERROR_KEY.

Here is a different:
The addErrors() method will append the error messages to the ActionMessages object if the ActionMessages object existed in the request object.

The saveErrors() method will replace the existing ActionMessages object with the new one that is passing in as an arugment to the method, instead of append it.

Here is a example showing the code fragment of their implemntation:

addErrors(HttpServletRequest request, ActionMessages errors)
{
  // ....
  ActionMessages requestErrors = (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
  if (requestErrors == null) {
     requestErrors = new ActionMessages();
  }

  requestErrors.add(errors);
  // ....
}

saveErrors(HttpServletRequest request, ActionMessages errors)
{
  //.....
  request.setAttribute(Globals.ERROR_KEY, errors);
}

Hope this help.


Go to topic 40063

Return to index page 369
Return to index page 368
Return to index page 367
Return to index page 366
Return to index page 365
Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360