You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by satyanarayana katta <sa...@gmail.com> on 2009/04/22 06:36:36 UTC

Issue in Action Chaining

Hi All,
I have a Action class

class BaseAction extends ActionSupport {
    private Sting data;

    public void getData() {
        return this.data;
    }

   public String setData(String data){
       this.data = data;
   }
}

class Action extends BaseAction{
    public String execute() throws Exception {
        System.out.println(getData());
        setData("abc");
        return "chain";
    }

    public String executeChain() throws Exception {
        System.out.println(getData());
        return "success"
    }
}

xml configuration:

<action name="test" class="Action">
<result name="chain">test2</result>
</action>

<action name="test2" class="Action" method="execute1">
<result name="chain"></result>
</action>



http://localhost:8080/test/test.action?data=ball

Output of execute:  ball
Output of execute1:  ball

I am expecting the out of execute1 as "abc"

Am I missing something please help me resolve the issue.

Rgds,

Satya

AW: Issue in Action Chaining

Posted by Anastasios Patrikis <An...@prodyna.de>.
Hi Satya,

in our project we have a base action with methods to read/write session attributes:

ServletActionContext.getRequest().getSession.getAttribute(name)
ServletActionContext.getRequest().getSession.setAttribute(name, object)

This may help.

Regards,

Anastasios.


-----Ursprüngliche Nachricht-----
Von: satyanarayana katta [mailto:saty.prasad@gmail.com] 
Gesendet: Mittwoch, 22. April 2009 08:04
An: Struts Users Mailing List; wesw@wantii.com
Betreff: Re: Issue in Action Chaining

Hi Wesw,
I also tried printing the object address and what you said is right!!  It is
creating a new object.  The object address is not same.  Is there any other
way of passing the data to the chained method?

I want to use the redirect as the last option!!

Rgds,

Satya

On Tue, Apr 21, 2009 at 10:22 PM, satyanarayana katta <saty.prasad@gmail.com
> wrote:

> Hi Wesw,
> Thanks for the reply.  Yes, I meant to say testChain().  Thanks for that.
>
> So, how is the old data being retained.  Does it take it from the http
> request and recreates the new instance?
>
> If that is the case, what other options do I have to get the changed data
> into the chained method?
>
> Thanks
>
> Satya
>
>
> On Tue, Apr 21, 2009 at 9:55 PM, Wes Wannemacher <we...@wantii.com> wrote:
>
>> On Wednesday 22 April 2009 00:36:36 satyanarayana katta wrote:
>> > Hi All,
>> > I have a Action class
>> >
>> > class BaseAction extends ActionSupport {
>> >     private Sting data;
>> >
>> >     public void getData() {
>> >         return this.data;
>> >     }
>> >
>> >    public String setData(String data){
>> >        this.data = data;
>> >    }
>> > }
>> >
>> > class Action extends BaseAction{
>> >     public String execute() throws Exception {
>> >         System.out.println(getData());
>> >         setData("abc");
>> >         return "chain";
>> >     }
>> >
>> >     public String executeChain() throws Exception {
>> >         System.out.println(getData());
>> >         return "success"
>> >     }
>> > }
>> >
>> > xml configuration:
>> >
>> > <action name="test" class="Action">
>> > <result name="chain">test2</result>
>> > </action>
>> >
>> > <action name="test2" class="Action" method="execute1">
>> > <result name="chain"></result>
>> > </action>
>> >
>> >
>> >
>> > http://localhost:8080/test/test.action?data=ball
>> >
>> > Output of execute:  ball
>> > Output of execute1:  ball
>> >
>> > I am expecting the out of execute1 as "abc"
>> >
>> > Am I missing something please help me resolve the issue.
>> >
>> > Rgds,
>> >
>> > Satya
>>
>> The configuration of test2 points to method execute1, but your action has
>> executeChain(). I assume that's a typo. My (somewhat educated) guess is
>> that
>> when you chain to the next action, even though it is the same class, a new
>> instance is created. In the new instance, setData(String) is never called
>> since it is only called in the execute method.
>>
>> -Wes
>> --
>>
>> Wes Wannemacher
>> Author - Struts 2 In Practice
>> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
>> http://www.manning.com/wannemacher
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

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


Re: Issue in Action Chaining

Posted by satyanarayana katta <sa...@gmail.com>.
Hi Wesw,
I also tried printing the object address and what you said is right!!  It is
creating a new object.  The object address is not same.  Is there any other
way of passing the data to the chained method?

I want to use the redirect as the last option!!

Rgds,

Satya

On Tue, Apr 21, 2009 at 10:22 PM, satyanarayana katta <saty.prasad@gmail.com
> wrote:

> Hi Wesw,
> Thanks for the reply.  Yes, I meant to say testChain().  Thanks for that.
>
> So, how is the old data being retained.  Does it take it from the http
> request and recreates the new instance?
>
> If that is the case, what other options do I have to get the changed data
> into the chained method?
>
> Thanks
>
> Satya
>
>
> On Tue, Apr 21, 2009 at 9:55 PM, Wes Wannemacher <we...@wantii.com> wrote:
>
>> On Wednesday 22 April 2009 00:36:36 satyanarayana katta wrote:
>> > Hi All,
>> > I have a Action class
>> >
>> > class BaseAction extends ActionSupport {
>> >     private Sting data;
>> >
>> >     public void getData() {
>> >         return this.data;
>> >     }
>> >
>> >    public String setData(String data){
>> >        this.data = data;
>> >    }
>> > }
>> >
>> > class Action extends BaseAction{
>> >     public String execute() throws Exception {
>> >         System.out.println(getData());
>> >         setData("abc");
>> >         return "chain";
>> >     }
>> >
>> >     public String executeChain() throws Exception {
>> >         System.out.println(getData());
>> >         return "success"
>> >     }
>> > }
>> >
>> > xml configuration:
>> >
>> > <action name="test" class="Action">
>> > <result name="chain">test2</result>
>> > </action>
>> >
>> > <action name="test2" class="Action" method="execute1">
>> > <result name="chain"></result>
>> > </action>
>> >
>> >
>> >
>> > http://localhost:8080/test/test.action?data=ball
>> >
>> > Output of execute:  ball
>> > Output of execute1:  ball
>> >
>> > I am expecting the out of execute1 as "abc"
>> >
>> > Am I missing something please help me resolve the issue.
>> >
>> > Rgds,
>> >
>> > Satya
>>
>> The configuration of test2 points to method execute1, but your action has
>> executeChain(). I assume that's a typo. My (somewhat educated) guess is
>> that
>> when you chain to the next action, even though it is the same class, a new
>> instance is created. In the new instance, setData(String) is never called
>> since it is only called in the execute method.
>>
>> -Wes
>> --
>>
>> Wes Wannemacher
>> Author - Struts 2 In Practice
>> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
>> http://www.manning.com/wannemacher
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Re: Issue in Action Chaining

Posted by satyanarayana katta <sa...@gmail.com>.
Hi Wesw,
Thanks for the reply.  Yes, I meant to say testChain().  Thanks for that.

So, how is the old data being retained.  Does it take it from the http
request and recreates the new instance?

If that is the case, what other options do I have to get the changed data
into the chained method?

Thanks

Satya

On Tue, Apr 21, 2009 at 9:55 PM, Wes Wannemacher <we...@wantii.com> wrote:

> On Wednesday 22 April 2009 00:36:36 satyanarayana katta wrote:
> > Hi All,
> > I have a Action class
> >
> > class BaseAction extends ActionSupport {
> >     private Sting data;
> >
> >     public void getData() {
> >         return this.data;
> >     }
> >
> >    public String setData(String data){
> >        this.data = data;
> >    }
> > }
> >
> > class Action extends BaseAction{
> >     public String execute() throws Exception {
> >         System.out.println(getData());
> >         setData("abc");
> >         return "chain";
> >     }
> >
> >     public String executeChain() throws Exception {
> >         System.out.println(getData());
> >         return "success"
> >     }
> > }
> >
> > xml configuration:
> >
> > <action name="test" class="Action">
> > <result name="chain">test2</result>
> > </action>
> >
> > <action name="test2" class="Action" method="execute1">
> > <result name="chain"></result>
> > </action>
> >
> >
> >
> > http://localhost:8080/test/test.action?data=ball
> >
> > Output of execute:  ball
> > Output of execute1:  ball
> >
> > I am expecting the out of execute1 as "abc"
> >
> > Am I missing something please help me resolve the issue.
> >
> > Rgds,
> >
> > Satya
>
> The configuration of test2 points to method execute1, but your action has
> executeChain(). I assume that's a typo. My (somewhat educated) guess is
> that
> when you chain to the next action, even though it is the same class, a new
> instance is created. In the new instance, setData(String) is never called
> since it is only called in the execute method.
>
> -Wes
> --
>
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Issue in Action Chaining

Posted by Wes Wannemacher <we...@wantii.com>.
On Wednesday 22 April 2009 00:36:36 satyanarayana katta wrote:
> Hi All,
> I have a Action class
>
> class BaseAction extends ActionSupport {
>     private Sting data;
>
>     public void getData() {
>         return this.data;
>     }
>
>    public String setData(String data){
>        this.data = data;
>    }
> }
>
> class Action extends BaseAction{
>     public String execute() throws Exception {
>         System.out.println(getData());
>         setData("abc");
>         return "chain";
>     }
>
>     public String executeChain() throws Exception {
>         System.out.println(getData());
>         return "success"
>     }
> }
>
> xml configuration:
>
> <action name="test" class="Action">
> <result name="chain">test2</result>
> </action>
>
> <action name="test2" class="Action" method="execute1">
> <result name="chain"></result>
> </action>
>
>
>
> http://localhost:8080/test/test.action?data=ball
>
> Output of execute:  ball
> Output of execute1:  ball
>
> I am expecting the out of execute1 as "abc"
>
> Am I missing something please help me resolve the issue.
>
> Rgds,
>
> Satya

The configuration of test2 points to method execute1, but your action has 
executeChain(). I assume that's a typo. My (somewhat educated) guess is that 
when you chain to the next action, even though it is the same class, a new 
instance is created. In the new instance, setData(String) is never called 
since it is only called in the execute method. 

-Wes
-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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


Re: Issue in Action Chaining

Posted by satyanarayana katta <sa...@gmail.com>.
No it doesn't work.  Chain is not accepting any of the parameters strings.
 Its going to the global error page directly.
Rgds,

Satya

On Tue, Apr 21, 2009 at 10:22 PM, Nils-Helge Garli Hegvik
<ni...@gmail.com>wrote:

> I'm not sure if this applies to the chain result, but you could give
> it a shot:
> http://struts.apache.org/2.1.6/docs/parameters-in-configuration-results.html
>
> Nils-H
>
> On Wed, Apr 22, 2009 at 6:36 AM, satyanarayana katta
> <sa...@gmail.com> wrote:
> > Hi All,
> > I have a Action class
> >
> > class BaseAction extends ActionSupport {
> >    private Sting data;
> >
> >    public void getData() {
> >        return this.data;
> >    }
> >
> >   public String setData(String data){
> >       this.data = data;
> >   }
> > }
> >
> > class Action extends BaseAction{
> >    public String execute() throws Exception {
> >        System.out.println(getData());
> >        setData("abc");
> >        return "chain";
> >    }
> >
> >    public String executeChain() throws Exception {
> >        System.out.println(getData());
> >        return "success"
> >    }
> > }
> >
> > xml configuration:
> >
> > <action name="test" class="Action">
> > <result name="chain">test2</result>
> > </action>
> >
> > <action name="test2" class="Action" method="execute1">
> > <result name="chain"></result>
> > </action>
> >
> >
> >
> > http://localhost:8080/test/test.action?data=ball
> >
> > Output of execute:  ball
> > Output of execute1:  ball
> >
> > I am expecting the out of execute1 as "abc"
> >
> > Am I missing something please help me resolve the issue.
> >
> > Rgds,
> >
> > Satya
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Issue in Action Chaining

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
I'm not sure if this applies to the chain result, but you could give
it a shot: http://struts.apache.org/2.1.6/docs/parameters-in-configuration-results.html

Nils-H

On Wed, Apr 22, 2009 at 6:36 AM, satyanarayana katta
<sa...@gmail.com> wrote:
> Hi All,
> I have a Action class
>
> class BaseAction extends ActionSupport {
>    private Sting data;
>
>    public void getData() {
>        return this.data;
>    }
>
>   public String setData(String data){
>       this.data = data;
>   }
> }
>
> class Action extends BaseAction{
>    public String execute() throws Exception {
>        System.out.println(getData());
>        setData("abc");
>        return "chain";
>    }
>
>    public String executeChain() throws Exception {
>        System.out.println(getData());
>        return "success"
>    }
> }
>
> xml configuration:
>
> <action name="test" class="Action">
> <result name="chain">test2</result>
> </action>
>
> <action name="test2" class="Action" method="execute1">
> <result name="chain"></result>
> </action>
>
>
>
> http://localhost:8080/test/test.action?data=ball
>
> Output of execute:  ball
> Output of execute1:  ball
>
> I am expecting the out of execute1 as "abc"
>
> Am I missing something please help me resolve the issue.
>
> Rgds,
>
> Satya
>

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