1

I am trying to find the replacement for org.apache.struts.actions.DispatchAction.types in Struts2.

Below code snippet:

if(types != null)
{
    if(types.length == forward.length)
    {
        select.add(type[0]);
    }
}

The forward is a string type object and select is a list type array.

Roman C
  • 49,761
  • 33
  • 66
  • 176
ajay
  • 11
  • 3
  • Can anyone please help me on this? – ajay Jan 18 '21 at 19:45
  • It is a feature of Struts 1.1 and I doesn't work with Struts2 unless you post your own implementation and explain your problem. – Roman C Jan 18 '21 at 21:31
  • Hi Roman, The code snippet I have provided is the part of big code so not possible for me to post whole code but can you help me to understand how org.apache.struts.actions.DispatchAction.types works in struts1 and is their any specific replacement for it in struts2. – ajay Jan 19 '21 at 06:14
  • What problem are you trying to solve? – Dave Newton Jan 19 '21 at 18:01

1 Answers1

0

The documentation for DispatchAction.types:

types protected java.lang.Class[] types The set of argument type classes for the reflected method call. These are the same for all calls, so calculate them only once.

There's not the same thing in Struts2. You should refresh your mind to understand that struts2 works differently than struts-1.

For example you can map your actions directly to the method. You can use SMI for method call like in this answer

You should place the annotation directly on the method. Because if you put it on the class the default method execute() is used for the mapping.

@ParentPackage("basePackage")
@Namespace("/")
@AllowedMethods("test")
public class UserAction {

    @Action(value = "userAction")
    public String test() {
        // your code
        rerurn Action.SUCCESS;
    }
}

or use wildcard mapping like this answer.

The action name is overridden if used in the same package. The action name maps to a specific method or execute.

You can use wildcard mapping to put a method name in the action.

<action name="*product" class="com.DispatchAction" method="{1}">
Roman C
  • 49,761
  • 33
  • 66
  • 176