user2329752
user2329752

Reputation: 77

How to get ActionRequest and ActionResponse in Render Phase on Liferay portlet?

how can I get ActionRequest and ActionResponse in Render Phase on Liferay portlet? I tried to add ActionRequest and ActionResponse params to my method:

@RenderMapping()
public String renderForm(@ModelAttribute MyForm form, BindingResult result, ActionRequest request, ActionResponse response)

But these params causes exception:

Current request is not of type [javax.portlet.ActionRequest]

Thanks.

Upvotes: 0

Views: 3581

Answers (2)

MrYo
MrYo

Reputation: 1817

I like to give some explanation of requests.

PortletRequest/ActionRequest/RenderRequest

PortletRequest

The PortletRequest is the parent of both. An ActionRequest and a RenderRequest are both different types of PortletRequest objects.

ActionRequest

An ActionRequest is valid during the action processing phase of the portlet. During this phase, the portlet hasn't completely decided how it is going to render itself, be it minimized, maximized, in edit mode or in veiw mode, etc.

RenderRequest

On the other hand, the RenderRequest is valid during the rendering phase of the portlet. At this point, the portlet knows how it is going to render itself, and certain changes such as window state, are not allowed.

So, all those request/response have different significance.

In your case, You can retrieve prameter in render phase by using getParameter but need to set value in action phase by using setRenderParameter.

Note: Portlet Specification (JSR 286 (Portlet 2.0))

major features of JSR 286 are:

  • Inter-Portlet Communication through events and public render parameters
  • Serving dynamically generated resources directly through portlets

Thanks.

Upvotes: 3

Tomas Pinos
Tomas Pinos

Reputation: 2862

ActionRequest and ActionResponse are tied to the action phase of portlet execution and can't be accessed during the render phase. During the render phase, only RenderRequest and RenderResponse are accessible. There's no such thing as an action request during a render phase.

If you want to access parameters from the action phase, use render parameters or the means of inter portlet communication.

A common practice is to set a render parameter during the action phase:

actionResponse.setRenderParameter("myParameter", "alligator");

In the render phase, you can read it from the render request:

renderRequest.getParameter("alligator");

For the means of inter portlet communication, see https://www.liferay.com/community/wiki/-/wiki/Main/Portlet+to+Portlet+Communication .

Upvotes: 2

Related Questions