You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Boon Leng <kb...@hotmail.com> on 2007/07/13 15:56:55 UTC

Migrate Struts 1 EventDispatchAction to Struts 2

May I know what is the best way to migrate Struts 1 EventDispatchAction to
Struts 2?

The following is my struts-config.xml where displaying form and submitting
form is using the same action name but execute different methods in the
action.

<action path="/*_add"
	type="org.springframework.web.struts.DelegatingActionProxy"
	name="{1}Form"
	attribute="{1}AddForm"
	parameter="insert, default=showForm"
	scope="request"
	validate="false">
	<forward name="input"	  path=".{1}.add"/>
	<forward name="success"	path="/{1}_add.do"   redirect="true"/>
	<forward name="cancel"	 path="/welcome.do"   redirect="true"/>
</action>

How do I convert it to Struts 2 mapping?
Any help would be appreciated. Thanks.

Regards,
Boon Leng
-- 
View this message in context: http://www.nabble.com/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11580060
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: Migrate Struts 1 EventDispatchAction to Struts 2

Posted by Laurie Harper <la...@holoweb.net>.
This is effectively possible 'out of the box' in S2. Just use the 
'method' attribute on a s:submit tag, for example, to control dispatch.

L.

Boon Leng wrote:
> Hi,
> 
> What I want to achieve is to migrate "EventDispatchAction", which means the
> methods will be called base on event, not base on request. Single action
> name can dispatch to multiple methods base on event triggered.
> And I would like to know is there anyway I can configure it in the action
> mapping? or I need to handle the event dispatch inside the action class?
> 
> 
> Thanks.
> 
> Regards,
> Boon Leng
> 
> 
> nuwan chandrasoma-2 wrote:
>> Hi,
>>
>> you can have a action mapping like this.
>>
>> <action name="sample_{*}" method="{1}" ...>
>>
>> and in your action class have 2 method according to you example
>>
>> public String add1() {
>>
>>     // your logic
>>
>>     return SUCCESS;
>>
>> }
>>
>> public String add2() {
>>
>>     // your logic
>>
>>     return SUCCESS;
>>
>> }
>>
>>
>> if a call  like this
>>     eg: /sample_add1.action the method add1 one will be called
>>
>> you can get more infromation from the below link
>>
>> http://struts.apache.org/2.x/docs/action-configuration.html#ActionConfiguration-WildcardMethod
>>
>> Thanks,
>>
>> Nuwan
>>
>> ----- Original Message ----- 
>> From: "Boon Leng" <kb...@hotmail.com>
>> To: <us...@struts.apache.org>
>> Sent: Saturday, July 14, 2007 4:45 AM
>> Subject: Re: Migrate Struts 1 EventDispatchAction to Struts 2
>>
>>
>>> Hi,
>>>
>>> I would like to know is there any class in struts 2 which is equivalent
>>> to
>>> EventDispatchAction?
>>> So that I can convert the following:
>>>    <action path="/sample_add" parameter="insert, default=showForm" ...>
>>> to something like this:
>>>    <action name="sample_add" method="insert, default=showForm" ...>
>>>
>>> and struts 2 will call the method showForm() by default and call insert()
>>> when button is clicked.
>>>
>>> Currently I have to dispatch the method inside my action class if I
>>> maintaining the same action name.
>>>
>>>    public String execute() throws Exception {
>>>        if (insert) {
>>>            return insert();
>>>        } else {
>>>            return showForm();
>>>        }
>>>    }
>>>
>>> or slip the mapping into 2 actions:
>>>    <action name="sample_add1" method="showForm" ...>
>>>    ...
>>>    <action name="sample_add2" method="insert" ...>
>>>
>>> Regards,
>>> Boon Leng
>>>
>>>
>>> Laurie Harper wrote:
>>>> What do you specifically need help with? Struts2 supports wildcard
>>>> action paths, dispatch to different methods in an action and
>>>> parameterized results (equivalent to the forwards in your S1 config). Is
>>>> there something in particular you're having trouble with?
>>>>
>>>> L.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11591032
>>> 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
>>>
>>
>> ---------------------------------------------------------------------
>> 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: Migrate Struts 1 EventDispatchAction to Struts 2

Posted by Boon Leng <kb...@hotmail.com>.
Hi,

What I want to achieve is to migrate "EventDispatchAction", which means the
methods will be called base on event, not base on request. Single action
name can dispatch to multiple methods base on event triggered.
And I would like to know is there anyway I can configure it in the action
mapping? or I need to handle the event dispatch inside the action class?


Thanks.

Regards,
Boon Leng


nuwan chandrasoma-2 wrote:
> 
> Hi,
> 
> you can have a action mapping like this.
> 
> <action name="sample_{*}" method="{1}" ...>
> 
> and in your action class have 2 method according to you example
> 
> public String add1() {
> 
>     // your logic
> 
>     return SUCCESS;
> 
> }
> 
> public String add2() {
> 
>     // your logic
> 
>     return SUCCESS;
> 
> }
> 
> 
> if a call  like this
>     eg: /sample_add1.action the method add1 one will be called
> 
> you can get more infromation from the below link
> 
> http://struts.apache.org/2.x/docs/action-configuration.html#ActionConfiguration-WildcardMethod
> 
> Thanks,
> 
> Nuwan
> 
> ----- Original Message ----- 
> From: "Boon Leng" <kb...@hotmail.com>
> To: <us...@struts.apache.org>
> Sent: Saturday, July 14, 2007 4:45 AM
> Subject: Re: Migrate Struts 1 EventDispatchAction to Struts 2
> 
> 
>>
>> Hi,
>>
>> I would like to know is there any class in struts 2 which is equivalent
>> to
>> EventDispatchAction?
>> So that I can convert the following:
>>    <action path="/sample_add" parameter="insert, default=showForm" ...>
>> to something like this:
>>    <action name="sample_add" method="insert, default=showForm" ...>
>>
>> and struts 2 will call the method showForm() by default and call insert()
>> when button is clicked.
>>
>> Currently I have to dispatch the method inside my action class if I
>> maintaining the same action name.
>>
>>    public String execute() throws Exception {
>>        if (insert) {
>>            return insert();
>>        } else {
>>            return showForm();
>>        }
>>    }
>>
>> or slip the mapping into 2 actions:
>>    <action name="sample_add1" method="showForm" ...>
>>    ...
>>    <action name="sample_add2" method="insert" ...>
>>
>> Regards,
>> Boon Leng
>>
>>
>> Laurie Harper wrote:
>>>
>>> What do you specifically need help with? Struts2 supports wildcard
>>> action paths, dispatch to different methods in an action and
>>> parameterized results (equivalent to the forwards in your S1 config). Is
>>> there something in particular you're having trouble with?
>>>
>>> L.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11591032
>> 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
>> 
> 
> 
> ---------------------------------------------------------------------
> 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/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11599257
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: Migrate Struts 1 EventDispatchAction to Struts 2

Posted by Nuwan Chandrasoma <my...@gmail.com>.
Hi,

you can have a action mapping like this.

<action name="sample_{*}" method="{1}" ...>

and in your action class have 2 method according to you example

public String add1() {

    // your logic

    return SUCCESS;

}

public String add2() {

    // your logic

    return SUCCESS;

}


if a call  like this
    eg: /sample_add1.action the method add1 one will be called

you can get more infromation from the below link

http://struts.apache.org/2.x/docs/action-configuration.html#ActionConfiguration-WildcardMethod

Thanks,

Nuwan

----- Original Message ----- 
From: "Boon Leng" <kb...@hotmail.com>
To: <us...@struts.apache.org>
Sent: Saturday, July 14, 2007 4:45 AM
Subject: Re: Migrate Struts 1 EventDispatchAction to Struts 2


>
> Hi,
>
> I would like to know is there any class in struts 2 which is equivalent to
> EventDispatchAction?
> So that I can convert the following:
>    <action path="/sample_add" parameter="insert, default=showForm" ...>
> to something like this:
>    <action name="sample_add" method="insert, default=showForm" ...>
>
> and struts 2 will call the method showForm() by default and call insert()
> when button is clicked.
>
> Currently I have to dispatch the method inside my action class if I
> maintaining the same action name.
>
>    public String execute() throws Exception {
>        if (insert) {
>            return insert();
>        } else {
>            return showForm();
>        }
>    }
>
> or slip the mapping into 2 actions:
>    <action name="sample_add1" method="showForm" ...>
>    ...
>    <action name="sample_add2" method="insert" ...>
>
> Regards,
> Boon Leng
>
>
> Laurie Harper wrote:
>>
>> What do you specifically need help with? Struts2 supports wildcard
>> action paths, dispatch to different methods in an action and
>> parameterized results (equivalent to the forwards in your S1 config). Is
>> there something in particular you're having trouble with?
>>
>> L.
>>
>>
>> ---------------------------------------------------------------------
>> 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/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11591032
> 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
> 


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


Re: Migrate Struts 1 EventDispatchAction to Struts 2

Posted by Boon Leng <kb...@hotmail.com>.
Hi,

I would like to know is there any class in struts 2 which is equivalent to
EventDispatchAction?
So that I can convert the following:
    <action path="/sample_add" parameter="insert, default=showForm" ...>
to something like this:
    <action name="sample_add" method="insert, default=showForm" ...>

and struts 2 will call the method showForm() by default and call insert()
when button is clicked.

Currently I have to dispatch the method inside my action class if I
maintaining the same action name.

    public String execute() throws Exception {
        if (insert) {
            return insert();
        } else {
            return showForm();
        }
    }

or slip the mapping into 2 actions:
    <action name="sample_add1" method="showForm" ...>
    ...
    <action name="sample_add2" method="insert" ...>

Regards,
Boon Leng


Laurie Harper wrote:
> 
> What do you specifically need help with? Struts2 supports wildcard 
> action paths, dispatch to different methods in an action and 
> parameterized results (equivalent to the forwards in your S1 config). Is 
> there something in particular you're having trouble with?
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> 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/Migrate-Struts-1-EventDispatchAction-to-Struts-2-tf4074633.html#a11591032
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: Migrate Struts 1 EventDispatchAction to Struts 2

Posted by Laurie Harper <la...@holoweb.net>.
Boon Leng wrote:
> May I know what is the best way to migrate Struts 1 EventDispatchAction to
> Struts 2?
> 
> The following is my struts-config.xml where displaying form and submitting
> form is using the same action name but execute different methods in the
> action.
> 
> <action path="/*_add"
> 	type="org.springframework.web.struts.DelegatingActionProxy"
> 	name="{1}Form"
> 	attribute="{1}AddForm"
> 	parameter="insert, default=showForm"
> 	scope="request"
> 	validate="false">
> 	<forward name="input"	  path=".{1}.add"/>
> 	<forward name="success"	path="/{1}_add.do"   redirect="true"/>
> 	<forward name="cancel"	 path="/welcome.do"   redirect="true"/>
> </action>
> 
> How do I convert it to Struts 2 mapping?
> Any help would be appreciated. Thanks.

What do you specifically need help with? Struts2 supports wildcard 
action paths, dispatch to different methods in an action and 
parameterized results (equivalent to the forwards in your S1 config). Is 
there something in particular you're having trouble with?

L.


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