Foren
Redirect to a render action
Thomas Kellerer, geändert vor 6 Jahren.
Redirect to a render action
Expert Beiträge: 490 Beitrittsdatum: 09.06.08 Neueste Beiträge
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:
The render action is defined like this:
What am I missing here?
I am using Liferay 7.0
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
Andrew Jardine, geändert vor 6 Jahren.
RE: Redirect to a render action
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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 --
GIve that a shot and see if it works.
// 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.
Sébastien Lamaison, geändert vor 6 Jahren.
RE: Redirect to a render action
New Member Beiträge: 24 Beitrittsdatum: 17.10.13 Neueste Beiträge
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
}
}