ActionForm and isCancelled...

2000-12-31 Thread Steven D. Wilkinson

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:




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

2001-01-05 Thread Craig R. McClanahan

"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:
> 
> 
> 
>

Have you looked at the  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  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...

2001-01-06 Thread Denis Hanson


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  tag?  It creates a cancel button with
a field
> name that the Struts controller servlet recognizes.

> If you use  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