At 3:58 PM -0500 3/24/04, Pady Srinivasan wrote:
I don't have sample code but are you looking for something like this:
// in Action execute...
ActionErrors errors = new ActionErrors();
// add errors...
...
// set in request
request.setAttribute("org.apache.struts.action.ERROR", errors);
// forward to same page...
When executing validation in an Action, you should use the Action
method "saveErrors" rather than directly manipulating the request
attributes; this guarantees that the errors will be placed in the
same place that other code is looking for them.
Here's the response I was drafting when this came in:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception
{
ActionMessages errors = processBusinessValidation(...);
if (!errors.isEmpty())
{
saveErrors(request,errors);
return mapping.getInputForward();
}
// normal business logic
return mapping.findForward(...);
}
private ActionMessages processBusinessValidation(...)
{
ActionMessages errors = new ActionMessages();
// execute validation, populate errors if necessary
return errors;
}
--
Joe Germuska
[EMAIL PROTECTED]
http://blog.germuska.com
"Imagine if every Thursday your shoes exploded if you tied them
the usual way. This happens to us all the time with computers, and
nobody thinks of complaining."
-- Jef Raskin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]