You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Till Nagel <ti...@netzministerium.de> on 2000/12/13 15:27:16 UTC

Actions with parameters

Is there any possibility to map actions with different parameters?

Something like:

<action path="/newsList" type="actions.NewsListAction" >
  <forward name="success" path="/newsList.jsp" />
</action>

<action path="/newsListAFew" type="actions.NewsListAction" >
  <forward name="success" path="/newsList.jsp" />
  <parameter key="number" value="10" />
</action>

There would be two advantages:
The designers do not have to be aware of parameters. They just call some
action.do's.
If we want to change the logic (i.e. the parameters) we must only change it
at struts-config.xml instead of everywhere referring to this action.

Regards,
Till


Re[2]: Actions with parameters

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Matthias,

Great! Month ago I search all docs for it...

Wednesday, December 13, 2000, 6:54:18 PM, you wrote:

MK> Hi Till,

>> Is there any possibility to map actions with different parameters?

MK> Yes, see below.

>> Something like:

>> <action path="/newsList" type="actions.NewsListAction" >
>>   <forward name="success" path="/newsList.jsp" />
>> </action>

>> <action path="/newsListAFew" type="actions.NewsListAction" >
>>   <forward name="success" path="/newsList.jsp" />
>>   <parameter key="number" value="10" />
>> </action>

MK> You have to add a (bean)property to your Action (in your example
MK> number). You can make the available to the action by (in 1.0) by

MK> <action path="/newsListAFew" type="actions.NewsListAction" >
MK>   <forward name="success" path="/newsList.jsp" />
MK>   <set-property property="number" value="10" />
MK> </action>

MK> The rest is left up to your action (ie, what you do with the property).

>> The designers do not have to be aware of parameters. They just call some
>> action.do's.
>> If we want to change the logic (i.e. the parameters) we must only change it
>> at struts-config.xml instead of everywhere referring to this action.

MK> I think, that's exactly the reason why <set-property> exists :) BTW, the
MK> property subelement is also valid for <forward>. See struts-config.dtd
MK> for more explanations.

MK> HTH.



-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: Actions with parameters

Posted by Till Nagel <ti...@netzministerium.de>.
Hi Matthias,

thanks so much. That's exact what I need.

> >   <parameter key="number" value="10" />
>   <set-property property="number" value="10" />
I was close.. ;)

Regards,
Till





Re: Actions with parameters

Posted by Matthias Kerkhoff <ma...@BESToffers.de>.
Hi Till,

> Is there any possibility to map actions with different parameters?

Yes, see below.

> Something like:

> <action path="/newsList" type="actions.NewsListAction" >
>   <forward name="success" path="/newsList.jsp" />
> </action>

> <action path="/newsListAFew" type="actions.NewsListAction" >
>   <forward name="success" path="/newsList.jsp" />
>   <parameter key="number" value="10" />
> </action>

You have to add a (bean)property to your Action (in your example
number). You can make the available to the action by (in 1.0) by

<action path="/newsListAFew" type="actions.NewsListAction" >
  <forward name="success" path="/newsList.jsp" />
  <set-property property="number" value="10" />
</action>

The rest is left up to your action (ie, what you do with the property).

> The designers do not have to be aware of parameters. They just call some
> action.do's.
> If we want to change the logic (i.e. the parameters) we must only change it
> at struts-config.xml instead of everywhere referring to this action.

I think, that's exactly the reason why <set-property> exists :) BTW, the
property subelement is also valid for <forward>. See struts-config.dtd
for more explanations.

HTH.
-- 
Matthias                        (mailto:make@BESToffers.de)



Re: Actions with parameters

Posted by Till Nagel <ti...@netzministerium.de>.
Hi,

> How about:
>     <action path="/newsListAFew?number=10"
>      type="actions.NewsListAction">
>         <forward name="success" path="/newsList.jsp"/>
>     </action>
How does it work? If I use it as in the example above there is no correct
mapping path (neither /newsListAFew.do nor /newsListAFew?number=10.do).

> The Struts example application uses this technique quite a bit.
Did you mean this?
<forward name="success" path="/editRegistration.do?action=Edit" />

That's not the mechanism I have searched for.
But if there is any easier way (without using own ActionMapping class) to
call actions with parameters, I would be glad to hear about.


Regards,
Till




Re: Actions with parameters

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.

Till Nagel wrote:

> Is there any possibility to map actions with different parameters?
>
> Something like:
>
> <action path="/newsList" type="actions.NewsListAction" >
>   <forward name="success" path="/newsList.jsp" />
> </action>
>
> <action path="/newsListAFew" type="actions.NewsListAction" >
>   <forward name="success" path="/newsList.jsp" />
>   <parameter key="number" value="10" />
> </action>
>
> There would be two advantages:
> The designers do not have to be aware of parameters. They just call some
> action.do's.
> If we want to change the logic (i.e. the parameters) we must only change it
> at struts-config.xml instead of everywhere referring to this action.
>

How about:

    <action path="/newsListAFew?number=10"
     type="actions.NewsListAction">
        <forward name="success" path="/newsList.jsp"/>
    </action>

The Struts example application uses this technique quite a bit.  At runtime, the
servlet container merges any request parameters on the path listed here with
those from the original request when it does the forward.

>
> Regards,
> Till

Craig McClanahan