You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "CRANFORD, CHRIS" <Ch...@setech.com> on 2010/08/13 20:09:01 UTC

Add ValueStack Object In Interceptor

I am trying to add an object to the ValueStack prior to invoking the
action; however my action is not able to see the added value in the
stack.  What is wrong with this code?

// Interceptor method
@Override
public String intercept(ActionInvocation invocation)
throws Exception {
  ValueStack stack = ActionContext.getContext().getValueStack();
  stack.setValue("my.test.key", new String("Hello World"));
  return invocation.invoke();
}

// In Action Class
public String testMethod()
throws Exception {
  String s = (String)
ActionContext.getContext().getValueStack().findValue("my.test.key");
  log.debug("my.test.key : " + (s != null ? s : "<null>");
}

I constantly get "my.test.key : <null>".

Why?

Chris


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


RE: Add ValueStack Object In Interceptor

Posted by "CRANFORD, CHRIS" <Ch...@setech.com>.
Ah that is likely the case.

Thanks!
Chris

> -----Original Message-----
> From: cimballi.cimballi@gmail.com [mailto:cimballi.cimballi@gmail.com]
> On Behalf Of Cimballi
> Sent: Friday, August 13, 2010 1:43 PM
> To: Struts Users Mailing List
> Subject: Re: Add ValueStack Object In Interceptor
> 
> Chris, the ParametersInterceptor clears the ValueStack, so depending
> on your stack maybe that's what's happening.
> 
> Cimballi
> 
> 
> On Fri, Aug 13, 2010 at 1:09 PM, CRANFORD, CHRIS
> <Ch...@setech.com> wrote:
> > I am trying to add an object to the ValueStack prior to invoking the
> > action; however my action is not able to see the added value in the
> > stack.  What is wrong with this code?
> >
> > // Interceptor method
> > @Override
> > public String intercept(ActionInvocation invocation)
> > throws Exception {
> >  ValueStack stack = ActionContext.getContext().getValueStack();
> >  stack.setValue("my.test.key", new String("Hello World"));
> >  return invocation.invoke();
> > }
> >
> > // In Action Class
> > public String testMethod()
> > throws Exception {
> >  String s = (String)
> > ActionContext.getContext().getValueStack().findValue("my.test.key");
> >  log.debug("my.test.key : " + (s != null ? s : "<null>");
> > }
> >
> > I constantly get "my.test.key : <null>".
> >
> > Why?
> >
> > Chris
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> 
> 
> --
> Cimballi
> Freelance - JAVA J2EE project leader
> http://cimballi.elance.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


Re: Add ValueStack Object In Interceptor

Posted by Cimballi <ci...@cimballi.net>.
Chris, the ParametersInterceptor clears the ValueStack, so depending
on your stack maybe that's what's happening.

Cimballi


On Fri, Aug 13, 2010 at 1:09 PM, CRANFORD, CHRIS
<Ch...@setech.com> wrote:
> I am trying to add an object to the ValueStack prior to invoking the
> action; however my action is not able to see the added value in the
> stack.  What is wrong with this code?
>
> // Interceptor method
> @Override
> public String intercept(ActionInvocation invocation)
> throws Exception {
>  ValueStack stack = ActionContext.getContext().getValueStack();
>  stack.setValue("my.test.key", new String("Hello World"));
>  return invocation.invoke();
> }
>
> // In Action Class
> public String testMethod()
> throws Exception {
>  String s = (String)
> ActionContext.getContext().getValueStack().findValue("my.test.key");
>  log.debug("my.test.key : " + (s != null ? s : "<null>");
> }
>
> I constantly get "my.test.key : <null>".
>
> Why?
>
> Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Cimballi
Freelance - JAVA J2EE project leader
http://cimballi.elance.com/

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