ReflectionAction

The class nstruts.actions.ReflectionAction allows to map any methods (also static ones) as an NStruts's action. The mapped methods must be compliant with the following signatures:

signature note
public nstruts.Forward MethodName( nstruts.ActionContext actionCtx, System.Web.HttpContext ctx ) public instance method
public static nstruts.Forward MethodName( nstruts.ActionContext actionCtx, System.Web.HttpContext ctx ) public static method

Configuration

Below is shown the ReflectionAction Configuration
<!-- Reflection Action -->
    <action type="nstruts.actions.ReflectionAction,nstruts" path="/[Action Name]">
      <init-params>
        <param name="type" value="[Action Type, Assembly]"/>
        <param name="method" value="[Method Name]"/>
      </init-params>
      <!-- Forward Declarations -->
    </action>

Example

This is the example provided within the NStruts's sample application (i.e. nstrutsweb)

TestReflectionAction.cs
namespace NStruts.Web.Actions
{
    public class TestReflectionAction
    {
        public Forward ActionA( ActionContext actionCtx, System.Web.HttpContext ctx )
        {
            ctx.Items["info"] = "ActionA";

            return actionCtx.Forwards["success"];
        }

        public Forward ActionB(ActionContext actionCtx, System.Web.HttpContext ctx)
        {
            ctx.Items["info"] = "ActionB";

            return actionCtx.Forwards["success"];
        }

        public static Forward ActionC(ActionContext actionCtx, System.Web.HttpContext ctx)
        {
            ctx.Items["info"] = "ActionC";

            return actionCtx.Forwards["success"];
        }
    }
}


TestReflectionAction configuration
<action type="nstruts.actions.ReflectionAction,nstruts" path="/actionA">
      <init-params>
        <param name="type" value="NStruts.Web.Actions.TestReflectionAction,nstrutsweb"/>
        <param name="method" value="ActionA"/>
      </init-params>
      <forward name="success" path="/ViewActionDetails.aspx" />
    </action>
    <action type="nstruts.actions.ReflectionAction,nstruts" path="/actionB">
      <init-params>
        <param name="type" value="NStruts.Web.Actions.TestReflectionAction,nstrutsweb"/>
        <param name="method" value="ActionB"/>
      </init-params>
      <forward name="success" path="/ViewActionDetails.aspx" />
    </action>
    <action type="nstruts.actions.ReflectionAction,nstruts" path="/actionC">
      <init-params>
        <param name="type" value="NStruts.Web.Actions.TestReflectionAction,nstrutsweb"/>
        <param name="method" value="ActionC"/>
      </init-params>
      <forward name="success" path="/ViewActionDetails.aspx" />
    </action>

Last edited Feb 14, 2007 at 8:00 AM by bsorrentino, version 1

Comments

No comments yet.