You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thom Burnett <th...@gmail.com> on 2007/02/05 16:04:06 UTC

Parameterizing the struts-config file

Can I use a parameter instead of a hard coded value in the mappings of a
struts-config.xml?
If so, how?

What I mean is:

I have a config file that looks like so:
    <action path="/myAction" type="com.softrek.conference.MyAction"
            name=" myForm" scope="request"
            validate="false" >
        <forward name="winMoney" redirect="true" path="winner.jsp" />
        <forward name="loser" path="thankYou.jsp" />
        ....
    </action>

This requires an Action that has exactly

'winMoney' and 'loser' as the strings in the mapping.findForward().
Can I use some sort of ForwardNames.WIN_MONEY instead? Or any other
parameter that will keep the strings identical. Ideally with only one place
to modify the string if it changes.

Is this possible? How?

Re: Parameterizing the struts-config file

Posted by Laurie Harper <la...@holoweb.net>.
Thom Burnett wrote:
> Can I use a parameter instead of a hard coded value in the mappings of a
> struts-config.xml?
> If so, how?
> 
> What I mean is:
> 
> I have a config file that looks like so:
>    <action path="/myAction" type="com.softrek.conference.MyAction"
>            name=" myForm" scope="request"
>            validate="false" >
>        <forward name="winMoney" redirect="true" path="winner.jsp" />
>        <forward name="loser" path="thankYou.jsp" />
>        ....
>    </action>
> 
> This requires an Action that has exactly
> 
> 'winMoney' and 'loser' as the strings in the mapping.findForward().
> Can I use some sort of ForwardNames.WIN_MONEY instead? Or any other
> parameter that will keep the strings identical. Ideally with only one place
> to modify the string if it changes.
> 
> Is this possible? How?

I don't believe there's any way to refer to a static Java constant from 
within struts-config.xml, unfortunately. However, there are a couple of 
projects which aim to replace XML configuration with annotations for 
Struts 1, which might at least allow you to collect everything into one 
place (the action class).

Another popular approach is to use a small set of 'well known' result 
names ('SUCCESS', 'ERROR', 'FAILURE', etc) which you can then reference 
as constants in your action classes. You still have to make sure that 
your action returns and your config match up, but with a limited set of 
possible values it'll be easier to spot if you have a mis-config.

L.


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