On Thu, 28 Nov 2002, ROSSEL Olivier wrote:

> Date: Thu, 28 Nov 2002 12:13:22 +0100
> From: ROSSEL Olivier <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: Passing an argument from struts-config.xml to an action.
>
> I read on the list that it is impossible to pass a property from
> struts-config.xml
> to an Action.
>
> Example:
>
> <action
>        .... >
> <set-property name="foo" value"bar"/>
> </action>
>
> except if you overload the ActionMapping used for that statement.
>
> Is it still the case in Struts-1.1 ?
>

It's not really true that you can't do this -- you just have to know how.
The key thing to remember is that the property setters you configure in
struts-config.xml affect the ActionMapping instance that is created, not
the Action class itself.

If you need only one configuration parameter, your best bet is to go ahead
and use the general purpose "parameter" property that ActionMapping
already supports:

  <action ... parameter="foo"/>

or (equivalently):

  <action ...>
    <set-property name="parameter" value="foo"/>
  </action>

which you can retrieve in the Action itself from the ActionMapping
instance that is passed to your perform() or execute() method:

  String param = mapping.getParameter();

((If you look at the source for DispatchAction, you'll see that this is
exactly how you configure the request parameter name that it should use to
figure out which method to call.))

If you need more parameters, you need to subclass the ActionMapping
implementation class ... there has been some examples of this in earlier
mail threads in the archive.

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to