You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kong xx <ko...@gmail.com> on 2007/05/16 13:41:22 UTC

Why I cannot use Interceptor to change the value of Action?

I need to use Interceptor to change a value of Action. For example, below is
my intercept method.

public String intercept(ActionInvocation invocation) throws Exception {
        String result;

        result = invocation.invoke();

        MyAction action = (MyAction)invocation.getAction();
        User user = action.getUser();
        user.setName("name2");
        action.setUser(user);

        return result;
}

here is my Action class:

public class MyAction extends ActionSupport {
    private User user;
    public MyAction() {
        user = new User();
    }
    public String execute() throws Exception {
        user.setName("name1");
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
}

In the jsp page, I use <c:property value="user.name"/> to display the user's
name, but it always display "name1". Why the interceptor cannot change the
value after invode invocation.invoke() method?

Thanks

-- 
Regards,
Fanbin

Re: Why I cannot use Interceptor to change the value of Action?

Posted by kongxx <ko...@gmail.com>.
Thanks for your help, I got it.



Dave Newton-4 wrote:
> 
> --- kong xx <ko...@gmail.com> wrote:
>> Why the interceptor cannot change the value after 
>> invode invocation.invoke() method?
> 
> http://struts.apache.org/2.x/docs/writing-interceptors.html
> 
> Note in particular the "big yellow box" section about
> when the "invoke" method returns!
> 
> d.
> 
> 
> 
>        
> ____________________________________________________________________________________Give
> spam the boot. Take control with tough spam protection in the all-new
> Yahoo! Mail Beta.
> http://advision.webevents.yahoo.com/mailbeta/newmail_html.html 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Why-I-cannot-use-Interceptor-to-change-the-value-of-Action--tf3764097.html#a10643197
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Why I cannot use Interceptor to change the value of Action?

Posted by Dave Newton <ne...@yahoo.com>.
--- kong xx <ko...@gmail.com> wrote:
> Why the interceptor cannot change the value after 
> invode invocation.invoke() method?

http://struts.apache.org/2.x/docs/writing-interceptors.html

Note in particular the "big yellow box" section about
when the "invoke" method returns!

d.



       
____________________________________________________________________________________Give spam the boot. Take control with tough spam protection in the all-new Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_html.html 

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