You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Juan Alvarado (Struts List)" <ju...@manduca.com> on 2001/11/29 20:35:30 UTC

Help with perform method

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
jalvarado@manduca.com
AOL Instant Messenger: juan2000@aol.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help with perform method

Posted by David Lauta <la...@gate.net>.
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
> > jalvarado@manduca.com
> > AOL Instant Messenger: juan2000@aol.com
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> Thank you,
> David Lauta
> lautad@gate.net
> (561)272-2698
> (561)289-0502 cell

--
Thank you,
David Lauta
lautad@gate.net
(561)272-2698
(561)289-0502 cell



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help with perform method

Posted by David Lauta <la...@gate.net>.
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
> jalvarado@manduca.com
> AOL Instant Messenger: juan2000@aol.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Thank you,
David Lauta
lautad@gate.net
(561)272-2698
(561)289-0502 cell


Re: Help with perform method

Posted by Joey Gibson <jt...@bravepoint.com>.
> 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>