Handling hundreds of actions in Struts2

Posted by Roberto on Stack Overflow See other posts from Stack Overflow or by Roberto
Published on 2010-03-22T09:56:38Z Indexed on 2010/03/22 12:51 UTC
Read the original article Hit count: 470

Filed under:
|
|
|

Hi all, I've inherited a struts 1 web application where, in order to reduce the number of Action classes (I guess this is the reason), lots of actions are mapped inside a single Action class, like:

public XXXAction() throws Exception{
     actions = new Hashtable();
     actions.put("/XXX/main/load", new Integer(0));
     actions.put("/XXX/main/save", new Integer(1));
            ......
}

public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
try
    {
        switch (((Integer) actions.get(action)).intValue())
        {
         case 0:
          loadXXXMain();
          break;
            case 1:
        .......

and so on (in some Action classes I have almost one hundred of these small actions).

Now I'm looking at migrate to struts2 and I would like to have a cleaner and better solution to handle this, maybe without having a single Action class for each of these small classes. What do you suggest? I don't like this solution, but I don't like having hundreds of Action classes....

Thanks! Roberto

© Stack Overflow or respective owner

Related posts about struts2

Related posts about struts