Liferay - Struts Action to Action forwarding

Discussions

Web tier: servlets, JSP, Web frameworks: Liferay - Struts Action to Action forwarding

  1. Liferay - Struts Action to Action forwarding (3 messages)

    Hi,

    Has anyone been able to create an Action in Liferay which forwards to an URL which is mapped as another action?

    I.E. - ActionForward forward = x.findForward("Y");

    where "Y"'s forward is /app/action.do

    If you did, how have you done it?

    I appreciate comments/workarounds/whatever if you had the opportunity to use Liferay and Struts.

    Rgs,

    Toledo

    Threaded Messages (3)

  2. you can try a snippet like the one below in struts-config.xml file.
    -------------------------------------------------------
    (action name="addDomainAction" parameter="addDomain"
       path="/addDomainAction"
       type="com.miracle.knowledge.web.action.DomainAction" validate="true")
       (forward name="success" path="/domainListAction.do"/)
                                     ----------------------
       (forward name="failure" path="/jsp/error.jsp"/)
      (/action>)
    ******
    (action name="domainListAction" parameter="domainsList"
       path="/domainListAction" scope="session"
       type="com.miracle.knowledge.web.action.DomainAction" validate="false")
       (forward name="success" path="/jsp/content/domainsList.jsp"/)
    (/action)
    ************

    here is the action class

    public class DomainAction extends Action {

    /*
    * (non-Javadoc)
    *
    * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
    * org.apache.struts.action.ActionForm,
    * javax.servlet.http.HttpServletRequest,
    * javax.servlet.http.HttpServletResponse)
    */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    ActionForward forward = null;
    String param = mapping.getParameter();
    if (param.intern() == "newDomain") {
    forward = executeNewDomain(mapping, form, request, response);
    }
    if (param.intern() == "domainsList") {
    forward = executeDomainsList(mapping, form, request, response);
    }
    if (param.intern() == "addDomain") {
    forward = addNewDomain(mapping, form, request, response);
    }
    return forward;
    }

    /**
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    *
    * @return
    *
    * @throws Exception
    */
    private ActionForward executeDomainsList(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    DomainCollection domains = DomainDataManager.getInstance().getDomainsList();
    HttpSession session = request.getSession();
    session.setAttribute("domains", domains);
    return mapping.findForward("success");
    }

    /**
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    *
    * @return
    *
    * @throws Exception
    */
    private ActionForward executeNewDomain(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    saveToken(request);
    return mapping.findForward("success");
    }

    /**
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    *
    * @return
    *
    * @throws Exception
    */
    private ActionForward addNewDomain(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    DomainForm domainForm = (DomainForm) form;
    // check if token is valid, but don't reset token

    if (isTokenValid(request)) {

    if (!domainForm.getDomainName().equals("")
    || domainForm.getDomainName() != null) {

    Integer result = (Integer) DomainService.getInstance()
    .getDomainService(IBusinessRules.INT_ADD, domainForm);
    saveToken(request);
    if (result.intValue() == 1) {
    return mapping.findForward("success");
    } else {
    return mapping.findForward("failure");
    }
    }
    }
    return mapping.findForward("alreadySubmitted");
    }
    }
  3. Fixed[ Go to top ]

    This has since been fixed in CVS.

    As a workaround, you will need to have your forward name be the same as the new action-mapping that you'd like to redirect to.

    <action path="/portal/test_redirect" type="com.liferay.portal.action.TestRedirectAction">
    <forward name="/c/portal/test" path="/c/portal/test" redirect="true" />
    </action>

    Note how the forward name and the path are the same.

    Cheers,

    Brian Kim
    Liferay, LLC
  4. Re: Fixed[ Go to top ]

    Hi Brian.. I'm trying to make an action to action forward.. but i have problems with it, it doesnt throw exception, but the portlet doesnt show up... Do I have to use de "c/" before the path and forward name? why is it necessary? Thanks. Sebastian.