Foren

Mistake in Liferay 6.0 Developer Guide???

Dirk Ulrich, geändert vor 12 Jahren.

Mistake in Liferay 6.0 Developer Guide???

Junior Member Beiträge: 42 Beitrittsdatum: 21.10.11 Neueste Beiträge
Hi.

I'm new to Liferay and currently running through the Developer Guide trying out the examples.
In the GreetingPortlet some messages shall be shown after storing a greeting message. To accomplish this, this code snippet is used in the edit.jsp:

<liferay-ui:success key="success" message="Greeting saved successfully!" />


The custom portlet class has this method:
	public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
		throws IOException, PortletException {
		PortletPreferences prefs = actionRequest.getPreferences();
		String greeting = actionRequest.getParameter("greeting");
		if (greeting != null) {
			try {
				prefs.setValue("greeting", greeting);
				prefs.store();
			} catch (Exception ex) {
				ex.printStackTrace(System.out);
				SessionErrors.add(actionRequest, "error");
			}
		}
		
		SessionMessages.add(actionRequest, "success");
		//SessionErrors.add(actionRequest, "error");
		
		//actionResponse.setPortletMode(PortletMode.EDIT);
		
		super.processAction(actionRequest, actionResponse);
	}


In the Developer Guide it is described that the success/error message will appear on the edit.jsp (as shown on page 35 of the Developer Guide) but my portlet always returns to the view.jsp after storing the new greeting message in the Preferences.

What do I have to do to display the success message on the edit.jsp (which also contains the form)? Is there a mistake in the Developer Guide??

Thank you.
thumbnail
Tejas Kanani, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Master Beiträge: 654 Beitrittsdatum: 06.01.09 Neueste Beiträge
Hi Dirk,

If it's possible, can you please share the war file?
Then we can have a look at it and might get the actual problem.

Regards,
Tejas
thumbnail
Hitoshi Ozawa, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Try setting copy-request-parameter in the portlet.xml file as described on page 33.
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
Hitoshi Ozawa:
Try setting copy-request-parameter in the portlet.xml file as described on page 33.


Hi Hitoshi,

Want to know more about copy-request-parameter.

I have read this at 33rd page but won't get much.

Would you please elaborate more on this.

Thanks,
Sagar Vyas
thumbnail
Tejas Kanani, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Master Beiträge: 654 Beitrittsdatum: 06.01.09 Neueste Beiträge
Sagar A Vyas:
Want to know more about copy-request-parameter.

Hi Sagar,

Just to elaborating more on copy-request-parameter.

There are basically two different phase in portlet.
1) Action
2) Render

When initially portlet gets loaded it will first execute Render phase and which will call doView() of the portlet.
Now lets say you have wrote some code which is calling processAction() of porltet with some request parameter passed. (i.e "greeting" on page 32)
You will be able to get this parameter in processAction by calling actionRequest.getParameter("greeting");
After returning from processAction it will again execute Render phase of portlet. (i.e doView()). Now if you try to get the value of "greeting" param over here. You will not get it.

To get those params in Render phase there are two ways.
1) Pass it from Action phase
- Just set RenderParameter as actionResponse.setRenderParameter("parameter-name", "value"); from processAction
- Get if using renderRequest.getParameter("parameter-name"); from Render phase.

2) Use copy-request-parameters
- Just set copy-request-parameters to true in portlet.xml, Which will be default copy all action parameters directly as render parameters.
<init-param>
<name>copy-request-parameters</name>
<value>true</value>
</init-param>

- So you can directly get action param values in Render phase without setting it as RenderParam from processAction.

I hope it gives you better idea about copy-request-parameters

Thanks,
Tejas Kanani
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
I hope it gives you better idea about copy-request-parameters


Thank you very much Tejas.

Really Good Explanation emoticon , I understood use of it.

Thanks,
Sagar Vyas
Dirk Ulrich, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Junior Member Beiträge: 42 Beitrittsdatum: 21.10.11 Neueste Beiträge
Setting copy-request-parameters to true in portlet.xml works well. Thank you.

I didn't set this value to true, because I wanted to exercise setting the parameters by myself. So which attribute is responsible for displaying the success or failure message? In edit.jsp I use the success or the error key respectively to display the messages but when I print out the request attributes/parameters I cannot see the respective values. Which are the responsible attributes for letting the JSP display the messages? I think I have to set them manually as well when I decide to set the copy-request-parameters to false...
Blais Che, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

New Member Beitrag: 1 Beitrittsdatum: 20.03.12 Neueste Beiträge
Hitoshi Ozawa:
Try setting copy-request-parameter in the portlet.xml file as described on page 33.

Hello, first time user here as well, who had the same issue. This works - thanks, but can someone explain how? The 'copy-request-parameters' apparently is for copying all action parameters directly as render parameters, but the manual does not say how it affects url redirection, or should the manual be updated? I have seen this same question asked multiple times before.. Thanks.
thumbnail
Sagar A Vyas, geändert vor 12 Jahren.

RE: Mistake in Liferay 6.0 Developer Guide???

Liferay Master Beiträge: 679 Beitrittsdatum: 17.04.09 Neueste Beiträge
Hi Dirk,

I think you need to override the doView(). method in your Portelt Controller.

In this example when you click on "Edit Greeting" it will redirect to process action method as it is actionURL as below.

<portlet:actionURL var="editGreetingURL">
<portlet:param name="jspPage" value="/edit.jsp" />
</portlet:actionURL>

Now as per life cycle of any MVC poerlet it will always call doView() method at and of processAction phase.
and default renderPage is view.jsp.

So here you need to do like

actionResponse.setRenderParameter("parameter-name", "edit"); in your Process Action Method

and

String jspName = renderRequest.getParameter("parameter-name"); in your doView() .

Now Write the logic like
if(jspName .equals("edit")
{
include(editJSP, renderRequest, renderResponse); // Render to edit page only
}

above will make sure that after submitting form it will stay on same page.

Hope this help.

Thanks,
Sagar Vyas