Wednesday, August 29, 2007

Passing params to Struts Mapping

We all come across situations where we have to pass params to Struts Action Mapping from Action class to create new ActionForward. As with most of my posts my intent is to learn and share.

Here is your Action Class

public class ResourceAction extends Action {


public ActionForward filter(ActionMapping mapping, ActionForm form, pServletRequest request,
HttpServletResponse response)

//other code here
//Original Forward

return mapping.findForward(ForwardConstants.SUCCESS);

//Create new Action Forward with additional params

ActionForward actionForward = mapping.findForward(ForwardConstants.SUCCESS);
ActionForward newActionForward = new ActionForward (actionForward);
newActionForward.setPath(actionForward.getPath()+ paramString); //create new Forward
return newActionForward;


}

}

No comments: