You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2007/01/24 20:12:09 UTC

[s1] Cancel request parameters and attributes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

I have two actions in my code that I want to be able to cancel out-of,
but neither of them is exciting enough to warrant a form bean and a trip
through the validator. I have found that Action.isCancelled does not
work when this is the case.

A simple hackaround is to do this in my action code:

	if(super.isCancelled(request)
	   || null !=
request.getParameter(org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY))
        {
             // handle cancellation
        }

This week, I'm upgrading to struts-1.3.5, which has the taglib JAR
separate from the core JAR, which means that I need to drag the taglib
JAR along with my upgrade, and I'd prefer not to do so (ignore the fact
that I need that JAR file for velocity-tools to work ;).

I figured it's time for me to get to the bottom of this problem, and I'm
finding myself getting quite confused reading through the code.

First, anyone who looks will note that the name of the "cancel" button
used by the struts form tag library (and the FormTool from
velocity-tools's struts tools) get the name
"org.apache.struts.taglib.html.CANCEL", which is the string value of
org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY.

So far, so good.

Now, to find out how Aciton.isCancelled works. It's pretty simple: it
checks for a request attribute:

    protected boolean isCancelled(HttpServletRequest request) {
        return (request.getAttribute(Globals.CANCEL_KEY) != null);
    }

The string value for Globals.CANCEL_KEY is
"org.apache.struts.action.CANCEL", which doesn't match up with that used
by the tag libaray. No big deal... it probably gets detected somewhere
in the request processor, right?

Well, I checked. The RequestProcessor only mentions "cancel" in the
processPopulate method, which delegates some processing to
RequestUtils.populate and then checks the request parameters for
Globals.CANCEL_KEY (or Globals.CANCEL_KEY_X for image submissions). No
luck there, so let's look at RequestUtils.populate.

RequestUtils.populate only sets properties on the ActionForm, and
doesn't mess with the request.

I can't seem to find the place where (under regular circumstances) the
request parameter "...taglib.html.CANCEL" gets converted into the
request attribute Globals.CANCEL.

Can someone help me understand how this works? I'd like to do the
"right" thing, here, and I need to understand how struts handles this
stuff during form submission so I can get it working when there is no form.

Any enlightenment would be appreciated.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFt6+J9CaO5/Lv0PARAuVxAJwM4BUVrZrFLBrDFUkq1Zgw6M9e7QCeLZFB
/E5sol+RWy14+Of0ZskDkZw=
=weT7
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [s1] Cancel request parameters and attributes [anyone?]

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,
Poking at this thread to see if I can get any bites.

- -chris

Christopher Schultz wrote:
> All,
> 
> I have two actions in my code that I want to be able to cancel out-of,
> but neither of them is exciting enough to warrant a form bean and a trip
> through the validator. I have found that Action.isCancelled does not
> work when this is the case.
> 
> A simple hackaround is to do this in my action code:
> 
> 	if(super.isCancelled(request)
> 	   || null !=
> request.getParameter(org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY))
>         {
>              // handle cancellation
>         }
> 
> This week, I'm upgrading to struts-1.3.5, which has the taglib JAR
> separate from the core JAR, which means that I need to drag the taglib
> JAR along with my upgrade, and I'd prefer not to do so (ignore the fact
> that I need that JAR file for velocity-tools to work ;).
> 
> I figured it's time for me to get to the bottom of this problem, and I'm
> finding myself getting quite confused reading through the code.
> 
> First, anyone who looks will note that the name of the "cancel" button
> used by the struts form tag library (and the FormTool from
> velocity-tools's struts tools) get the name
> "org.apache.struts.taglib.html.CANCEL", which is the string value of
> org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY.
> 
> So far, so good.
> 
> Now, to find out how Aciton.isCancelled works. It's pretty simple: it
> checks for a request attribute:
> 
>     protected boolean isCancelled(HttpServletRequest request) {
>         return (request.getAttribute(Globals.CANCEL_KEY) != null);
>     }
> 
> The string value for Globals.CANCEL_KEY is
> "org.apache.struts.action.CANCEL", which doesn't match up with that used
> by the tag libaray. No big deal... it probably gets detected somewhere
> in the request processor, right?
> 
> Well, I checked. The RequestProcessor only mentions "cancel" in the
> processPopulate method, which delegates some processing to
> RequestUtils.populate and then checks the request parameters for
> Globals.CANCEL_KEY (or Globals.CANCEL_KEY_X for image submissions). No
> luck there, so let's look at RequestUtils.populate.
> 
> RequestUtils.populate only sets properties on the ActionForm, and
> doesn't mess with the request.
> 
> I can't seem to find the place where (under regular circumstances) the
> request parameter "...taglib.html.CANCEL" gets converted into the
> request attribute Globals.CANCEL.
> 
> Can someone help me understand how this works? I'd like to do the
> "right" thing, here, and I need to understand how struts handles this
> stuff during form submission so I can get it working when there is no form.
> 
> Any enlightenment would be appreciated.
> 
> -chris

- ---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFukwY9CaO5/Lv0PARArKVAKCwrci12h/ga7Ux7PwIuCrclCQDQwCbBFLh
Tzb4gamCkvGoK+7WbcEwH5k=
=c6OG
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org