You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Subcontrato Online2 <su...@aranzadi.es> on 2005/02/28 13:02:51 UTC

Extend struts action-mapping forward tag

Hi!

I need to add a new attribute "resultcode" in the action-mapping <forward>
tag. Example:
<forward contextRelative="true" name="invalidNews"
path="/WEB-INF/jsp/fsMarcos.jsp" resultcode="01"/>

This attribute will define a result code for the action the user requested.

I'm thinking in extending the ActionMapping,ActionForward classes and
implement this features.

Does anyone tried this?
Any other idea?

Thanks a lot.


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


Re: Extend struts action-mapping forward tag

Posted by Hubert Rabago <hr...@gmail.com>.
You can achieve this using the subclass support in struts-config.xml.
Create your custom ActionForward class and provide it with your property:

public class CustomActionForward
        extends ActionForward {
    private int returnCode = 0;
    public int getReturnCode() { return returnCode; }
    public void setReturnCode(int returnCode) { this.returnCode = returnCode; }
}


Use the className attribute to specify your custom class, and use
<set-property> to configure it:

        <action path="/somePath"
            type="my.package.SomeAction">
            <forward name="success" path="/somePage.jsp" 
                className="my.package.CustomActionForward">
                <set-property property="returnCode" value="10"/>
            </forward>
        </action>


Then in your SomeAction:

        ActionForward forward = mapping.findForward("success");
        if (forward instanceof CustomActionForward) {
            returnCode = ((CustomActionForward) forward).getReturnCode();
            System.out.println("returnCode = " + returnCode);
        }
        // do whatever with your return code
        ...
        return forward;


hth,
Hubert


On Mon, 28 Feb 2005 13:02:51 +0100, Subcontrato Online2
<su...@aranzadi.es> wrote:
> Hi!
> 
> I need to add a new attribute "resultcode" in the action-mapping <forward>
> tag. Example:
> <forward contextRelative="true" name="invalidNews"
> path="/WEB-INF/jsp/fsMarcos.jsp" resultcode="01"/>
> 
> This attribute will define a result code for the action the user requested.
> 
> I'm thinking in extending the ActionMapping,ActionForward classes and
> implement this features.
> 
> Does anyone tried this?
> Any other idea?
> 
> Thanks a lot.
>

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