You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Steven D. Wilkinson" <st...@acm.org> on 2001/01/01 00:46:27 UTC

ActionForm and isCancelled...

I had a issue with a form and the cancel button.
I'm using the cancel button from the submit tag library in my jsp:
<form:submit property="cancel">
    <bean:message key="button.cancel"/>
</form:submit>

When I display the Form and the user wants to Cancel I have to look for the
cancel button parameter using the same technique as the
isCancelled(HttpServletRequest request) method within the Action class.  Is this
common enough that some could add an isCancelled(HttpServletRequest request)
within the ActionForm class?

My dilemma is that I don't want to perform any validation if the user presses
the cancel button.  Here is what I did to my ActionForm class.

...
import org.apache.struts.taglib.form.Constants;
...

   public ActionErrors validate(ActionMapping mapping,
           HttpServletRequest request) {
      ActionErrors errors = new ActionErrors();
      if(isCancelled(request)) {
         return errors;
      }
      ....
   }

    protected boolean isCancelled(HttpServletRequest request) {
      return (request.getParameter(Constants.CANCEL_PROPERTY) != null);
    }

This would eliminate duplicate code in ActionForm classes.  I know I could
extend the ActionForm and use that, but I think this is something that a lot of
people could use.  Just my opinion though.

What does everyone else think?

Thanks in advance,
Steve



RE: ActionForm and isCancelled...

Posted by Denis Hanson <de...@mediaone.net>.
Hello Craig,

I'd like to suggest that struts add something like 'cancel="true"' (or
'validate="false"') parameter to the form:image tag so that input images can
be used as cancel buttons.

Thanks,

Denis Hanson


"Craig R. McClanahan" wrote:

> Have you looked at the <form:cancel> tag?  It creates a cancel button with
a field
> name that the Struts controller servlet recognizes.

> If you use <form:cancel> and the user presses that button, Struts will
recognize
> this and never call the validate() method of your ActionForm.  It will
simply pass
> control on to your Action, where you can check for this by calling:

>    if (isCancelled(request)) {
>        ... do something ...
>    }

Craig



Re: ActionForm and isCancelled...

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Steven D. Wilkinson" wrote:

> I had a issue with a form and the cancel button.
> I'm using the cancel button from the submit tag library in my jsp:
> <form:submit property="cancel">
>     <bean:message key="button.cancel"/>
> </form:submit>
>

Have you looked at the <form:cancel> tag?  It creates a cancel button with a field
name that the Struts controller servlet recognizes.

>
> When I display the Form and the user wants to Cancel I have to look for the
> cancel button parameter using the same technique as the
> isCancelled(HttpServletRequest request) method within the Action class.  Is this
> common enough that some could add an isCancelled(HttpServletRequest request)
> within the ActionForm class?
>
> My dilemma is that I don't want to perform any validation if the user presses
> the cancel button.  Here is what I did to my ActionForm class.
>

If you use <form:cancel> and the user presses that button, Struts will recognize
this and never call the validate() method of your ActionForm.  It will simply pass
control on to your Action, where you can check for this by calling:

    if (isCancelled(request)) {
        ... do something ...
    }

Craig