Avoiding Multiple Submits(Refresh page) in Liferay
We often see after submitting the form and refresh the page you will see the same result will be adding in the DB.
So how to get rid of this?
Here we have 2 options to eliminate this behaviour.
1. By Declaring the tag in the liferay-portlet.xml after <icon> tag
<action-url-redirect> true </action-url-redirect>
2.After doing our logic we can redirect to specified URL by using actionResponse.
actionResponse.sendRedirect(PortalUtil.getLayoutURL(themeDisplay.getLayout(),themeDisplay));
Here we are redirecting to the friendly url of that page.
The above will be redirect to the below URL as
//group/test/test1----- (group/<your-community-name>/pageName).
Thanks!
ReplyDeleteHi
ReplyDeleteI followed your example true for avoid duplicate submission in forms and redirected to another page after the submission by response.setRenderParameter("jspPage","page"); and forward the value by request.setAttribute("","");
But I can't get the value in the page request.getAttribute() method. It displaying null. But its working if I removed true in liferay-portlet.xml.
I need both should be work. Can you please help me on this?
Hi Arasan,
ReplyDeleteSee this thread " http://www.liferay.com/community/forums/-/message_boards/message/13943569 ".
They are using the following snipets to redirect
String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest), portletName,
themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
redirectURL.setParameter("jspPage", "your jsp path");
actionResponse.sendRedirect(redirectURL.toString());
Let me know if you required something else
DeleteThanks Mr. Venka for your response,
DeleteI asked the solution for side effect of disallowing to use share the value between two pages by request.getAttribute("")
Eventhough your code works fine, I can't share the value by request.getAttribute("") method. By removing true only I can share the value by request.getAttribute("") method. It's my issue.
By Accessing via portlet session only I can able to share
DeleteHi tkarasan,
DeleteI fill explain you step by step how to achive that
1. In liferay-portlet.xml : true
2. In class
actionResponse.setRenderParameter("name", "venka");
3. In JSP
if (request.getParameter("name") == null) {
out.println("value is null.");
} else {
out.println("Hello your name is "+request. getParameter("name")+"!");
}
I have tested this . Don't use session it may have unnecessarily probs
Let me know if anything else required.
Also Thanks for pointing out. I will update blog.
DeleteThis comment has been removed by the author.
DeleteThanks Mr.Venka
DeleteYour code works fine. Thank you for your valuable reply.
Thanks, Good to hear from you..
DeleteHi,
DeleteI am using the doView and render method in the same portlet, in which I have added the above tag. In this method will not support for setRenderParameter(String,String); Because it will support for Action methods only. Then how I can pass the value from doView or render method to jsp page.
Hello I have tried this its working..but it is not giving me the success message...
ReplyDelete