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
-
Liferay - Struts Action to Action forwarding (3 messages)
- Posted by: Marcos Toledo
- Posted on: October 26 2005 13:30 EDT
Threaded Messages (3)
- Liferay - Struts Action to Action forwarding by umar ali on November 06 2005 13:53 EST
- Fixed by Brian Kim on November 10 2005 16:29 EST
- Re: Fixed by Sebastian Casti??eiras on July 19 2006 16:27 EDT
-
Liferay - Struts Action to Action forwarding[ Go to top ]
- Posted by: umar ali
- Posted on: November 06 2005 13:53 EST
- in response to Marcos Toledo
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");
}
} -
Fixed[ Go to top ]
- Posted by: Brian Kim
- Posted on: November 10 2005 16:29 EST
- in response to Marcos Toledo
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 -
Re: Fixed[ Go to top ]
- Posted by: Sebastian Casti??eiras
- Posted on: July 19 2006 16:27 EDT
- in response to Brian Kim
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.