Forums de discussion
PRG Pattern - post redirect get - faces-redirect=true
Bart Van den Abeele, modifié il y a 11 années.
PRG Pattern - post redirect get - faces-redirect=true
New Member Publications: 10 Date d'inscription: 22/06/12 Publications récentes
Hi,
I'm developing a simple JSF 2 portlet with richfaces. I can't seem to get "faces-redirect=true" to work. I have a form with a submit button. When i submit everything works fine. When i press refresh in the browser, the post action is triggerd again. To prevent it from triggering again, i added "?faces-redirect=true" to my action. However, this does not work. When i refresh after i submitted the form, the form is submitted a second time.
Am i doing something wrong? Or is this not yet supported?
grtz,
Bart
I'm developing a simple JSF 2 portlet with richfaces. I can't seem to get "faces-redirect=true" to work. I have a form with a submit button. When i submit everything works fine. When i press refresh in the browser, the post action is triggerd again. To prevent it from triggering again, i added "?faces-redirect=true" to my action. However, this does not work. When i refresh after i submitted the form, the form is submitted a second time.
public String save() throws SystemException
{
if (book.getBookId() == 0)
{
long id = CounterLocalServiceUtil.increment(Book.class.getName());
book.setBookId(id);
BookLocalServiceUtil.addBook(book);
}
else
{
BookLocalServiceUtil.updateBook(book);
}
return "books?faces-redirect=true";
}
public String delete(Book book) throws SystemException, PortalException, IOException
{
BookLocalServiceUtil.deleteBook(book);
return "books?faces-redirect=true";
}
Am i doing something wrong? Or is this not yet supported?
grtz,
Bart
Neil Griffin, modifié il y a 11 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Liferay Faces Bridge supports redirection during navigation. It can be done with faces-redirect=tue (like you are using) or by specifying <redirect /> in a navigation-rule inside of the WEB-INF/faces-config.xml descriptor.
If you're doing the redirect with Ajax enabled like this, then it should work:
<h:commandButton action="#{backingBean.save}">
<f:ajax execute="@form" />
</h:commandButton>
This is because the jsf.js library that ships with JSF2 will do a redirect via JavaScript.
But if you're not using it with Ajax (full postback that invokes the ACTION_PHASE) of the portlet lifecycle, then it's not going to work in Liferay Portal. because (for performance reasons) the portlet container implementation of Liferay Portal does not implement the post-redirect-get pattern within the portlet lifecycle. When this happens, the redirect will be ignored and treated like normal JSF navigation.
If you're doing the redirect with Ajax enabled like this, then it should work:
<h:commandButton action="#{backingBean.save}">
<f:ajax execute="@form" />
</h:commandButton>
This is because the jsf.js library that ships with JSF2 will do a redirect via JavaScript.
But if you're not using it with Ajax (full postback that invokes the ACTION_PHASE) of the portlet lifecycle, then it's not going to work in Liferay Portal. because (for performance reasons) the portlet container implementation of Liferay Portal does not implement the post-redirect-get pattern within the portlet lifecycle. When this happens, the redirect will be ignored and treated like normal JSF navigation.
Bart Van den Abeele, modifié il y a 11 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
New Member Publications: 10 Date d'inscription: 22/06/12 Publications récentes
Hi Neil,
The solution you proposed works. Thx for the clear explanation!
grtz,
Bart
The solution you proposed works. Thx for the clear explanation!
grtz,
Bart
Peter Mesotten, modifié il y a 9 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
Junior Member Publications: 45 Date d'inscription: 04/02/09 Publications récentes
Hi Neil,
Does that mean that POST-REDIRECT-GET will never work for JSF 1, because we don't have Ajax there?
Are there any alternatives that work for JSF 1?
Thanks!
Does that mean that POST-REDIRECT-GET will never work for JSF 1, because we don't have Ajax there?
Are there any alternatives that work for JSF 1?
Thanks!
Juan Gonzalez, modifié il y a 9 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
You can check PrettyFaces project, I used successfully some years ago:
http://ocpsoft.org/prettyfaces/
http://ocpsoft.org/prettyfaces/
Juan Gonzalez, modifié il y a 9 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
BTW, I've never tested in Liferay (only in non-portlet environment).
Neil Griffin, modifié il y a 9 années.
RE: PRG Pattern - post redirect get - faces-redirect=true
Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
@Juan: We are using PrettyFaces to simulate Liferay Friendly URLs with the new showcase-webapp we are developing for Liferay Faces. Since it is a servlet-based technology and due to the experience we've gathered, I would say that it is largely incompatible with portlets.
@Peter: We recently fixed FACES-1557 which (I think) may give you the "redirect" functionality you require. For Liferay 6.2, I would recommend that you download the 2.2.5-ga6-SNAPSHOT versions of the Liferay Faces jar artifacts from the snapshot repository and see if it works for you. For Liferay 6.1, download version 2.1.5-ga6-SNAPSHOT.
@Peter: We recently fixed FACES-1557 which (I think) may give you the "redirect" functionality you require. For Liferay 6.2, I would recommend that you download the 2.2.5-ga6-SNAPSHOT versions of the Liferay Faces jar artifacts from the snapshot repository and see if it works for you. For Liferay 6.1, download version 2.1.5-ga6-SNAPSHOT.