Submit Once, Validate Twice -- but how ?

2004-03-24 Thread Frank Schaare
Hi,

just read this article on husted.com and it seems to be good advice.

When the user submits a page, passes validation without errors, is there 
a chance to validate business logic in the action ?

Therefor i need to
- make my validation,
- get an errors object,
- store the error,
- put the errors object in the request and
- return to input page.
Has anyone some sample code / suggestions / articles / sources hoe to 
achieve this ?

Thx

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Submit Once, Validate Twice -- but how ?

2004-03-24 Thread Pady Srinivasan

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...


Thanks
 
-- pady
[EMAIL PROTECTED]
 

-Original Message-
From: Frank Schaare [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 24, 2004 3:35 PM
To: Struts Users Mailing List
Subject: Submit Once, Validate Twice -- but how ?

Hi,

just read this article on husted.com and it seems to be good advice.

When the user submits a page, passes validation without errors, is there 
a chance to validate business logic in the action ?

Therefor i need to
- make my validation,
- get an errors object,
- store the error,
- put the errors object in the request and
- return to input page.

Has anyone some sample code / suggestions / articles / sources hoe to 
achieve this ?

Thx

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__

__
This email has been scanned by the Heroix e-mail Security System
__

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Submit Once, Validate Twice -- but how ?

2004-03-24 Thread Frank Schaare
Hi,

thank you, that helps.

Now i still need to know how to access the input page (set in action 
mapping with the input=sample.jsp tag)...

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...
Thanks


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Submit Once, Validate Twice -- but how ?

2004-03-24 Thread Joe Germuska
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]


Re: Submit Once, Validate Twice -- but how ?

2004-03-24 Thread Haroon Rafique
On Today at 9:58pm, FS=Frank Schaare [EMAIL PROTECTED] wrote:

FS Hi,
FS 
FS thank you, that helps.
FS 
FS Now i still need to know how to access the input page (set in action 
FS mapping with the input=sample.jsp tag)...

Hopefully you will see Joe's response in the same thread, which has the 
following line in it:

 return mapping.getInputForward();

Later,
--
Haroon Rafique
[EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]