Help with perform method

2001-11-29 Thread Juan Alvarado \(Struts List\)

Hi:

I have a class called AddUserAction which of course extends Action. In the
perform method what I will do is add a record to a table in a database. The
values I will add I will of course get from the form object the method takes
as one of its parameters.

What I would like to do is that if there is some type of error in this
method, I want to be able to do a mapping.findForward(failure) and at the
same time be able to include some type of error message to the user in the
failure page. My failure page is probably the same form the user filled out,
but the second time around I would like to display the error message.

Any help with this topic is greatly appreciated.

Thanks

**
Juan Alvarado
Internet Developer -- Manduca Management
(786)552-0504
[EMAIL PROTECTED]
AOL Instant Messenger: [EMAIL PROTECTED]


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




Re: Help with perform method

2001-11-29 Thread Joey Gibson

 What I would like to do is that if there is some type
 of error in this
 method, I want to be able to do a
 mapping.findForward(failure) and at the
 same time be able to include some type of error
 message to the user in the
 failure page. My failure page is probably the same
 form the user filled out,
 but the second time around I would like to display
 the error message.

This is what ActionError, ActionErrors and html:errors/ is for. 

perform(...)
{
   // ... processing ...
   ActionErrors errors = new ActionErrors();
   ActionError err = new ActionError(error.username.taken);
   errors.add(ActionErrors.GLOBAL_ERROR, err);

   saveErrors(request, response);

   return new ActionForward(mapping.getInput());
}

Then in the jsp page, you can simply add:

html:errors/

somewhere conspicuous to get the errors to display.

Joey

--
Sent via jApache.org

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




Re: Help with perform method

2001-11-29 Thread David Lauta

I sounds like you need to do three things:

1) Struts-config.xml add an input
 action-mappings
  action
   name=StrutsTestForm
   path=/StrutsTest
   type=web.StrutsTestAction
   input=/StrutsTest.jsp
   attribute=StrutsTestForm   

   forward name=success path=/StrutsTest.jsp  /
  /action
Input is the path to return to on errors
2) In the JSP add the error tag  html:errors/

3) In either the Form.Validate() method or the action Validate method create the
ActionErrors
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
 {
  // Check for empties or invalids here
  boolean noErrors = true;
  ActionErrors ae = null;
// Soething bad detected here
   if ( ae == null )
   {
ae = new ActionErrors();
noErrors = false;

   }
   ae.add(ActionErrors.GLOBAL_ERROR, new ActionError(some property from your
resource) );
 }
  if ( noErrors )
  {
   return null; // No Errors found
  }
  return ae;
}



Juan Alvarado (Struts List) wrote:

 Hi:

 I have a class called AddUserAction which of course extends Action. In the
 perform method what I will do is add a record to a table in a database. The
 values I will add I will of course get from the form object the method takes
 as one of its parameters.

 What I would like to do is that if there is some type of error in this
 method, I want to be able to do a mapping.findForward(failure) and at the
 same time be able to include some type of error message to the user in the
 failure page. My failure page is probably the same form the user filled out,
 but the second time around I would like to display the error message.

 Any help with this topic is greatly appreciated.

 Thanks

 **
 Juan Alvarado
 Internet Developer -- Manduca Management
 (786)552-0504
 [EMAIL PROTECTED]
 AOL Instant Messenger: [EMAIL PROTECTED]

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

--
Thank you,
David Lauta
[EMAIL PROTECTED]
(561)272-2698
(561)289-0502 cell




Re: Help with perform method

2001-11-29 Thread David Lauta

I meant action Perfor() method

David Lauta wrote:

 I sounds like you need to do three things:

 1) Struts-config.xml add an input
  action-mappings
   action
name=StrutsTestForm
path=/StrutsTest
type=web.StrutsTestAction
input=/StrutsTest.jsp
attribute=StrutsTestForm   

forward name=success path=/StrutsTest.jsp  /
   /action
 Input is the path to return to on errors
 2) In the JSP add the error tag  html:errors/

 3) In either the Form.Validate() method or the action Validate method create the
 ActionErrors
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
  {
   // Check for empties or invalids here
   boolean noErrors = true;
   ActionErrors ae = null;
 // Soething bad detected here
if ( ae == null )
{
 ae = new ActionErrors();
 noErrors = false;

}
ae.add(ActionErrors.GLOBAL_ERROR, new ActionError(some property from your
 resource) );
  }
   if ( noErrors )
   {
return null; // No Errors found
   }
   return ae;
 }

 Juan Alvarado (Struts List) wrote:

  Hi:
 
  I have a class called AddUserAction which of course extends Action. In the
  perform method what I will do is add a record to a table in a database. The
  values I will add I will of course get from the form object the method takes
  as one of its parameters.
 
  What I would like to do is that if there is some type of error in this
  method, I want to be able to do a mapping.findForward(failure) and at the
  same time be able to include some type of error message to the user in the
  failure page. My failure page is probably the same form the user filled out,
  but the second time around I would like to display the error message.
 
  Any help with this topic is greatly appreciated.
 
  Thanks
 
  **
  Juan Alvarado
  Internet Developer -- Manduca Management
  (786)552-0504
  [EMAIL PROTECTED]
  AOL Instant Messenger: [EMAIL PROTECTED]
 
  --
  To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
  For additional commands, e-mail: mailto:[EMAIL PROTECTED]

 --
 Thank you,
 David Lauta
 [EMAIL PROTECTED]
 (561)272-2698
 (561)289-0502 cell

--
Thank you,
David Lauta
[EMAIL PROTECTED]
(561)272-2698
(561)289-0502 cell



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