留言板

If i save any entity and again refresh page, it store again the same

Atul Soni,修改在8 年前。

If i save any entity and again refresh page, it store again the same

New Member 帖子: 7 加入日期: 15-2-13 最近的帖子
Hi all !
I have the form which save any custom entity in database, and then again i refresh the page that time it again going to save , so can you please suggest me that how to prevent above stuff. Please answer me as soon as possible.
thumbnail
David H Nebinger,修改在8 年前。

RE: If i save any entity and again refresh page, it store again the same

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Obviously you do not understand the portal specification.

At it's core, a portlet must deal with two phases:

1. Action phase - This is where your portlet should take actions such as updating a database or manipulating an entity or whatever.
2. Render phase - This is where your portlet should be rendering itself, but it should not be making any changes. The render phase can be called numerous times while a portlet is on a portal page and therefore it must not change anything.

If you're getting saves every time you refresh then you've let some of your action logic bleed into your render phase.
Atul Soni,修改在8 年前。

RE: If i save any entity and again refresh page, it store again the same

New Member 帖子: 7 加入日期: 15-2-13 最近的帖子
Thank you David for reply !

So i have to manage this manually right.?
thumbnail
David H Nebinger,修改在8 年前。

RE: If i save any entity and again refresh page, it store again the same

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
yes
thumbnail
Amos Fong,修改在8 年前。

RE: If i save any entity and again refresh page, it store again the same

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
Is your form doing a POST or GET? If it's post, most browsers will catch a refresh and stop you.

But, you'll want probably want to do a sendRedirect anyway back to a render URL after you process the action which I think Manish is hinting at.
thumbnail
Manish Yadav,修改在8 年前。

RE: If i save any entity and again refresh page, it store again the same

Expert 帖子: 493 加入日期: 12-5-26 最近的帖子
Hello ,
you have to set <action-url-redirect> value to true after <icon> tag inside liferay-portlet.xml which is set false by default.

for eg :-

<portlet>
<portlet-name>test-portlet</portlet-name>
<icon>/icon.png</icon>
<action-url-redirect>true</action-url-redirect>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portlet-javascript>/js/main.js</header-portlet-javascript>
<footer-portlet-javascript>
/js/main.js
</footer-portlet-javascript>

</portlet>