You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Shneyderman <al...@law.columbia.edu> on 2003/07/29 01:23:37 UTC

Action Chaining problems

I have a need to chain actions and my code looks like:

OperationConfig oc = new OperationConfig ();
        
if ((oc.getStep () == null) || "".equals (oc.getStep ().trim ())) {
   oc.setStep (DEFAULT_STEP);
}

if ((oc.getOperation () == null) || "".equals (oc.getOperation ().trim
())) {
   oc.setOperation (DEFAULT_OP);
}
        
ActionForward af = mapping.findForward ("navigate.step" + oc.getStep
());
        
//System.out.println ("Hash code: " + ((Object) request).hashCode ());
//System.out.println ("To string: " + ((Object) request).toString ());

if (af != null) {
   request.setAttribute (Constants.REQATTRIBUTE_OPCFG, oc);

//for (Enumeration enum = request.getAttributeNames();
enum.hasMoreElements // (); ) {
//   String key = (String) enum.nextElement ();
//     System.out.println ("Key: " + key + "; Class: " +
//request.getAttribute (key).getClass().getName ());
//            }
            
   return af;
} else { // TODO: this is an error.
   return null;
}

Now when my action that I chain to gets the request it actualy does not
get the attribute that I set. As the matter of fact my request object is
completely different instance (which I really could care less about, as
long the content stays there).

Can someone shed some light on this?
My redirect is false.

Thanks,
Alex.

PS here is the output of the commented code:

Hash code: 5738457
To string: org.apache.catalina.core.ApplicationHttpRequest@578fd9
Key: javax.servlet.request.cipher_suite; Class: java.lang.String
Key: org.apache.struts.action.MESSAGE; Class:
org.apache.struts.util.PropertyMessageResources
Key: javax.servlet.request.key_size; Class: java.lang.Integer
Key: org.apache.struts.action.mapping.instance; Class:
org.apache.struts.action.ActionMapping
Key: Logon; Class: org.apache.struts.validator.DynaValidatorForm
Key: edu.columbia.law.gls.opcfg; Class:
edu.columbia.law.gls.OperationConfig
Key: NavigatorForm; Class: org.apache.struts.action.DynaActionForm
Key: org.apache.struts.action.MODULE; Class:
org.apache.struts.config.impl.ModuleConfigImpl

Similar output of the action chained to:


Hash code: 4727831
To string: org.apache.coyote.tomcat4.CoyoteRequestFacade@482417
-- it is null
Key: javax.servlet.request.cipher_suite; Class: java.lang.String
Key: org.apache.struts.action.MESSAGE; Class:
org.apache.struts.util.PropertyMessageResources
Key: javax.servlet.request.key_size; Class: java.lang.Integer
Key: org.apache.struts.action.mapping.instance; Class:
org.apache.struts.action.ActionMapping
Key: org.apache.struts.action.MODULE; Class:
org.apache.struts.config.impl.ModuleConfigImpl

As you can see the request and its content is changed. Why is that?



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


RE: Action Chaining problems

Posted by Alex Shneyderman <al...@law.columbia.edu>.
I went thru the Struts' source and I can not see that this behaviour is
what's supposed to happen. If my redirect is set to false, all struts
does is 

At the end of RequestProcessor.process method the following method is
called:

   processActionForward(request, response, forward);

   this in trun calls
   processForwardConfig( request, response, forward );

   this in turn executes 

        if (forward.getRedirect()) {
            // only prepend context path for relative uri
            if (uri.startsWith("/")) {
                uri = request.getContextPath() + uri;
            }
            response.sendRedirect(response.encodeRedirectURL(uri));
            
        } else {
            doForward(uri, request, response);
        }

   now since my redirect is false
    doForward will be executed and it looks like the following
    RequestDispatcher rd =
getServletContext().getRequestDispatcher(uri);
    rd.forward(request, response);

As far as I can see Struts does not do it but container somehow does
create a new instance of request (which as I said I could care less
about, as long as the content stays the same). Now is this expected
behavior of RequestDispatcher.forward?

I do not think so. I just can't see where this is happening. If anyone
can point me to the place where I can clearly see the code that should
correspond to the behavior I am seeing, that would be very helpful.
Otherwise, I am stuck with assigneing attributes to the session object,
which I would hate to do.

Thanks,
Alex.

> Dear Alex,
> 
> Whenever you do action chaining, for the second action, it will always
be
> considred as a new request from the browser. So the insances will be
new
> and the attributes will not be there. This is the behaviour of action
> chaining.
> 
> It is recomended not to use action chaining if you want to pass
attributes
> in the request and use the attributes of the action forms.
> You can extend the actions instead...
> 
> Siva
> 
> Alex Shneyderman wrote:
> 
> > I have a need to chain actions and my code looks like:
> >
> > OperationConfig oc = new OperationConfig ();
> >
> > if ((oc.getStep () == null) || "".equals (oc.getStep ().trim ())) {
> >    oc.setStep (DEFAULT_STEP);
> > }
> >
> > if ((oc.getOperation () == null) || "".equals (oc.getOperation
().trim
> > ())) {
> >    oc.setOperation (DEFAULT_OP);
> > }
> >
> > ActionForward af = mapping.findForward ("navigate.step" + oc.getStep
> > ());
> >
> > //System.out.println ("Hash code: " + ((Object) request).hashCode
());
> > //System.out.println ("To string: " + ((Object) request).toString
());
> >
> > if (af != null) {
> >    request.setAttribute (Constants.REQATTRIBUTE_OPCFG, oc);
> >
> > //for (Enumeration enum = request.getAttributeNames();
> > enum.hasMoreElements // (); ) {
> > //   String key = (String) enum.nextElement ();
> > //     System.out.println ("Key: " + key + "; Class: " +
> > //request.getAttribute (key).getClass().getName ());
> > //            }
> >
> >    return af;
> > } else { // TODO: this is an error.
> >    return null;
> > }
> >
> > Now when my action that I chain to gets the request it actualy does
not
> > get the attribute that I set. As the matter of fact my request
object is
> > completely different instance (which I really could care less about,
as
> > long the content stays there).
> >
> > Can someone shed some light on this?
> > My redirect is false.
> >
> > Thanks,
> > Alex.
> >
> > PS here is the output of the commented code:
> >
> > Hash code: 5738457
> > To string: org.apache.catalina.core.ApplicationHttpRequest@578fd9
> > Key: javax.servlet.request.cipher_suite; Class: java.lang.String
> > Key: org.apache.struts.action.MESSAGE; Class:
> > org.apache.struts.util.PropertyMessageResources
> > Key: javax.servlet.request.key_size; Class: java.lang.Integer
> > Key: org.apache.struts.action.mapping.instance; Class:
> > org.apache.struts.action.ActionMapping
> > Key: Logon; Class: org.apache.struts.validator.DynaValidatorForm
> > Key: edu.columbia.law.gls.opcfg; Class:
> > edu.columbia.law.gls.OperationConfig
> > Key: NavigatorForm; Class: org.apache.struts.action.DynaActionForm
> > Key: org.apache.struts.action.MODULE; Class:
> > org.apache.struts.config.impl.ModuleConfigImpl
> >
> > Similar output of the action chained to:
> >
> > Hash code: 4727831
> > To string: org.apache.coyote.tomcat4.CoyoteRequestFacade@482417
> > -- it is null
> > Key: javax.servlet.request.cipher_suite; Class: java.lang.String
> > Key: org.apache.struts.action.MESSAGE; Class:
> > org.apache.struts.util.PropertyMessageResources
> > Key: javax.servlet.request.key_size; Class: java.lang.Integer
> > Key: org.apache.struts.action.mapping.instance; Class:
> > org.apache.struts.action.ActionMapping
> > Key: org.apache.struts.action.MODULE; Class:
> > org.apache.struts.config.impl.ModuleConfigImpl
> >
> > As you can see the request and its content is changed. Why is that?
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


Re: Action Chaining problems

Posted by Siva <si...@india.adventnet.com>.
Dear Alex,

Whenever you do action chaining, for the second action, it will always be
considred as a new request from the browser. So the insances will be new
and the attributes will not be there. This is the behaviour of action
chaining.

It is recomended not to use action chaining if you want to pass attributes
in the request and use the attributes of the action forms.
You can extend the actions instead...

Siva

Alex Shneyderman wrote:

> I have a need to chain actions and my code looks like:
>
> OperationConfig oc = new OperationConfig ();
>
> if ((oc.getStep () == null) || "".equals (oc.getStep ().trim ())) {
>    oc.setStep (DEFAULT_STEP);
> }
>
> if ((oc.getOperation () == null) || "".equals (oc.getOperation ().trim
> ())) {
>    oc.setOperation (DEFAULT_OP);
> }
>
> ActionForward af = mapping.findForward ("navigate.step" + oc.getStep
> ());
>
> //System.out.println ("Hash code: " + ((Object) request).hashCode ());
> //System.out.println ("To string: " + ((Object) request).toString ());
>
> if (af != null) {
>    request.setAttribute (Constants.REQATTRIBUTE_OPCFG, oc);
>
> //for (Enumeration enum = request.getAttributeNames();
> enum.hasMoreElements // (); ) {
> //   String key = (String) enum.nextElement ();
> //     System.out.println ("Key: " + key + "; Class: " +
> //request.getAttribute (key).getClass().getName ());
> //            }
>
>    return af;
> } else { // TODO: this is an error.
>    return null;
> }
>
> Now when my action that I chain to gets the request it actualy does not
> get the attribute that I set. As the matter of fact my request object is
> completely different instance (which I really could care less about, as
> long the content stays there).
>
> Can someone shed some light on this?
> My redirect is false.
>
> Thanks,
> Alex.
>
> PS here is the output of the commented code:
>
> Hash code: 5738457
> To string: org.apache.catalina.core.ApplicationHttpRequest@578fd9
> Key: javax.servlet.request.cipher_suite; Class: java.lang.String
> Key: org.apache.struts.action.MESSAGE; Class:
> org.apache.struts.util.PropertyMessageResources
> Key: javax.servlet.request.key_size; Class: java.lang.Integer
> Key: org.apache.struts.action.mapping.instance; Class:
> org.apache.struts.action.ActionMapping
> Key: Logon; Class: org.apache.struts.validator.DynaValidatorForm
> Key: edu.columbia.law.gls.opcfg; Class:
> edu.columbia.law.gls.OperationConfig
> Key: NavigatorForm; Class: org.apache.struts.action.DynaActionForm
> Key: org.apache.struts.action.MODULE; Class:
> org.apache.struts.config.impl.ModuleConfigImpl
>
> Similar output of the action chained to:
>
> Hash code: 4727831
> To string: org.apache.coyote.tomcat4.CoyoteRequestFacade@482417
> -- it is null
> Key: javax.servlet.request.cipher_suite; Class: java.lang.String
> Key: org.apache.struts.action.MESSAGE; Class:
> org.apache.struts.util.PropertyMessageResources
> Key: javax.servlet.request.key_size; Class: java.lang.Integer
> Key: org.apache.struts.action.mapping.instance; Class:
> org.apache.struts.action.ActionMapping
> Key: org.apache.struts.action.MODULE; Class:
> org.apache.struts.config.impl.ModuleConfigImpl
>
> As you can see the request and its content is changed. Why is that?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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


Re: Action Chaining problems

Posted by Michael Ruppin <mr...@yahoo.com>.
What's in your struts-config action mapping?  If you
have redirect=true this is expected.

--- Alex Shneyderman <al...@law.columbia.edu> wrote:
> I have a need to chain actions and my code looks
> like:
> 
> OperationConfig oc = new OperationConfig ();
>         
> if ((oc.getStep () == null) || "".equals (oc.getStep
> ().trim ())) {
>    oc.setStep (DEFAULT_STEP);
> }
> 
> if ((oc.getOperation () == null) || "".equals
> (oc.getOperation ().trim
> ())) {
>    oc.setOperation (DEFAULT_OP);
> }
>         
> ActionForward af = mapping.findForward
> ("navigate.step" + oc.getStep
> ());
>         
> //System.out.println ("Hash code: " + ((Object)
> request).hashCode ());
> //System.out.println ("To string: " + ((Object)
> request).toString ());
> 
> if (af != null) {
>    request.setAttribute
> (Constants.REQATTRIBUTE_OPCFG, oc);
> 
> //for (Enumeration enum =
> request.getAttributeNames();
> enum.hasMoreElements // (); ) {
> //   String key = (String) enum.nextElement ();
> //     System.out.println ("Key: " + key + "; Class:
> " +
> //request.getAttribute (key).getClass().getName ());
> //            }
>             
>    return af;
> } else { // TODO: this is an error.
>    return null;
> }
> 
> Now when my action that I chain to gets the request
> it actualy does not
> get the attribute that I set. As the matter of fact
> my request object is
> completely different instance (which I really could
> care less about, as
> long the content stays there).
> 
> Can someone shed some light on this?
> My redirect is false.
> 
> Thanks,
> Alex.
> 
> PS here is the output of the commented code:
> 
> Hash code: 5738457
> To string:
>
org.apache.catalina.core.ApplicationHttpRequest@578fd9
> Key: javax.servlet.request.cipher_suite; Class:
> java.lang.String
> Key: org.apache.struts.action.MESSAGE; Class:
> org.apache.struts.util.PropertyMessageResources
> Key: javax.servlet.request.key_size; Class:
> java.lang.Integer
> Key: org.apache.struts.action.mapping.instance;
> Class:
> org.apache.struts.action.ActionMapping
> Key: Logon; Class:
> org.apache.struts.validator.DynaValidatorForm
> Key: edu.columbia.law.gls.opcfg; Class:
> edu.columbia.law.gls.OperationConfig
> Key: NavigatorForm; Class:
> org.apache.struts.action.DynaActionForm
> Key: org.apache.struts.action.MODULE; Class:
> org.apache.struts.config.impl.ModuleConfigImpl
> 
> Similar output of the action chained to:
> 
> 
> Hash code: 4727831
> To string:
> org.apache.coyote.tomcat4.CoyoteRequestFacade@482417
> -- it is null
> Key: javax.servlet.request.cipher_suite; Class:
> java.lang.String
> Key: org.apache.struts.action.MESSAGE; Class:
> org.apache.struts.util.PropertyMessageResources
> Key: javax.servlet.request.key_size; Class:
> java.lang.Integer
> Key: org.apache.struts.action.mapping.instance;
> Class:
> org.apache.struts.action.ActionMapping
> Key: org.apache.struts.action.MODULE; Class:
> org.apache.struts.config.impl.ModuleConfigImpl
> 
> As you can see the request and its content is
> changed. Why is that?
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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