RE: prevent back and refresh button to avoid form resubmission (Liferay 7)

pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
we are doing payment related functionality,so after the payment completed if user can click on back button or refresh the transaction deduct twice , so how can we avoid to user for form submission . we are using Liferay7
thumbnail
Mohammed yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi , 
   After action you can create a render url and redirect to it  or  create a render url and send it to mvcrender command
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed,
Now , I am doing like below code , after form submission we calling action method , in action method wen storing data in DB and after that we rendering to next page their we will showing him sucess message like "Account created successfully"

  demo code as like below,
  public void createUser(ActionRequest req, ActionResponse res ){

  // inserting logic here 

 
  actionResponse.setRenderParameter("mvcPath","/pages/result.jsp");
 }
  
but , here issue is like on result.jsp , when he refreshing , or clicking back button then our createUser method again executing 

Thanks & Regards,
  Pradip 
thumbnail
Mohammed yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi ,
   Instead setting the render parameter you create a render url and send redirect
        PortletURL portletURL =  PortletURLFactoryUtil.create(actionRequest, themeDisplay.getPortletDisplay().getId(), PortletRequest.RENDER_PHASE);
            portletURL.setPortletMode(LiferayPortletMode.VIEW);        
            portletURL.setParameter("jspPage", "/pages/result.jsp");
            actionResponse.sendRedirect(portletURL.toString()); 
thumbnail
Santosh B Biradar, modified 6 Years ago. Junior Member Posts: 41 Join Date: 8/4/15 Recent Posts
Hi,

we can use "com.liferay.portlet.action-url-redirect=true" property for avoiding re submission of form.
thumbnail
Mohammed yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
This i think its not supported from Liferay 7 onwards, in 6.2 it was used for avoiding re-submission.
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Mohammed yasin:

This i think its not supported from Liferay 7 onwards, in 6.2 it was used for avoiding re-submission.



I'm assuming you mean com.liferay.portlet.action-url-redirect?

According to the documentation (https://portal.liferay.dev/docs/7-2/reference/-/knowledge_base/r/portlet-descriptor-to-osgi-service-property-map) it's still there, which points to it being supported - or a bug if it doesn't work.

In fact, the notation that Santosh B Biradar used, is the OSGi property notation (available since 7.0), not the 6.2 xml/dtd notation.
thumbnail
Mohammed yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi Olaf Kock,
Your right "com.liferay.portlet.action-url-redirect=true" is working fine .Thanks for correcting