struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Piker" <>
Subject RE: Action Question
Date Wed, 23 Mar 2005 20:16:24 GMT
Should also point out that it's usually better to use
mapping.getInputForward() in these situations (instead of defining a
"failure" forward), since validator will always redirect the user back
to the "input" location if there's a validation error (and this is
usually the same place you want them to go for business rule

Only time you wouldn't want to do this is if you're sending the user to
a different page/form to "fix" the business rule errors (e.g. rule
overrides).  But if the intention is to send them back to their original
form with their original data, use the input mapping.

- Scott

-----Original Message-----
From: Fogleson, Allen [] 
Sent: Wednesday, March 23, 2005 1:26 PM
To: Struts Users Mailing List
Subject: RE: Action Question

Before forwarding to failure try this... 


  Public ActionForward execute(Mapping mapping Form form, ...) {

    YourFormClass newuserbeanform = (YourFormClass)form;

    boolean recordInsert = userbo.insertNewUser();
//By The way this looks backwards... I thought true was a success???
    if (recordInsert) {
      request.setAttribute("newuserbean", newuserbeanform);
      actionforward = mapping.findForward("Failure");
    } else {
      actionforward = mapping.findForward("Success");

That will make the current form available to the jsp and it should show
the data you have in it.


-----Original Message-----
From: Scott Purcell []
Sent: Wednesday, March 23, 2005 11:55 AM
Subject: Action Question

I have a form, which has an attached bean. I am doing validation, so I
have good data going to my action.
In the action, I take the bean with good data, and hand it to a DTO
object which updates the database with the new user supplied
information. What can I do in the Action if my DTO object returns false
(Could not update database because of some condition).  I know I can
find a mapping and send it somewhere, but the user just filled out a
large form, and I would like to send them back to the form, where the
data is, and show them a message there. I tried using the Failure (see
below) but when it goes to the newUser.jsp page it is blank. The data
they just entered is not there.
I know how to do this in a ActionForm, but how in an Action?
Here is my action mapping:
    <action path="/newUser-submit"
      <forward name="Success" path="/jsp/admin/mainAdmin.jsp" />
      <forward name="Failure" path="/jsp/admin/newUser.jsp" />

Here is the action piece.
BeanUtils.copyProperties(usersbean, userbo);
    boolean recordInsert = userbo.insertNewUser();
    if (recordInsert) {
      actionforward = mapping.findForward("Failure");
    } else {
      actionforward = mapping.findForward("Success");
    return actionforward;
I just would like to be able to return them to their form where they
just entered all the data, and let them try again.



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message