掲示板

Redirect to a render action

6年前 に Thomas Kellerer によって更新されました。

Redirect to a render action

Expert 投稿: 490 参加年月日: 08/06/09 最新の投稿
I have a MVCPortlet that processes the user input in a BaseMVCActionCommand.

When that processing is done, I would like to invoke a specific render action to show the result of the previous step.

I tried the following in the doProcessAction() method of my ActionCommand:

actionResponse.setRenderParameter("id", Long.toString(id)); // the ID needed by the render action
actionResponse.setRenderParameter("mvcRenderCommandName", "showDetails");


The render action is defined like this:

@Component(
    immediate = true,
    property = {
        "javax.portlet.name=my_portlet"
        "mvc.command.name=showDetails"
    },
    service = MVCRenderCommand.class
)
public class DetailsAction
    implements MVCRenderCommand {
.... 
}
My DetailsAction is called but the corresponding JSP page is not shown and what's worse the render parameter "id" is null inside the render action.

What am I missing here?
I am using Liferay 7.0
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: Redirect to a render action

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
I haven't tried this yet in 7.0, but in the last version (and no reason why it should not work here) you could accomplish what you are trying to do with a PortletURL. So something like this --

// assuming same portlet, same page
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long plid = themeDisplay.getPlid();
String portletId = XXXPortletKeys.YOUR_PORTLET_NAME;
PortletURL renderURL = PortletURLFactoryUtil.createRenderURL(actionRequest, portletId, plid, PorletRequest.RENDER_PHASE);
renderURL.setParameter(...);
renderURL.setParameter(...);
...

try{
    actionResponse.sendRedirect(renderURL.toString());
}
catch(Exception e) {
     // hand error
}


GIve that a shot and see if it works.
6年前 に Sébastien Lamaison によって更新されました。

RE: Redirect to a render action

New Member 投稿: 24 参加年月日: 13/10/17 最新の投稿
Landed here for the same need, and based on Andrew's answer, I wrote this for Liferay 7 (from what I saw on the portlet:renderURL tag) :


	public void redirectToMVCRenderAction(ActionRequest actionRequest, ActionResponse actionResponse) {
		String portletId = XXXPortletKeys.YOUR_PORTLET_NAME;
		
		ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
		
		PortletResponse portletResponse = (PortletResponse) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
		LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(portletResponse);

		LiferayPortletURL renderUrl = liferayPortletResponse.createLiferayPortletURL(themeDisplay.getPlid(), portletId, PortletRequest.RENDER_PHASE);

		renderUrl.setParameter("your_param", "your-param-value");
		...

		try {
			actionResponse.sendRedirect(renderUrl.toString());
		} catch (Exception e) {
			// handle error
		}
	}