I am currently investigating JSF in my current work.
In the past, while using Spring and Struts, I always do a PRG (Post-Redirect-Get) whenever
I do something that could potentially update the model.
In JSF, I have read that the framework internally makes a forward request. So is it safe
to assume that I should add redirect in those transaction that could potentially update the model?
My usecase for example. I have a JSP that display products in shopping cart, user can perform payment transaction.
I dont want them to pay twice so I want to perform redirect
<navigation-rule>
<from-view-id>/viewCart.jsp</from-view-id>
<navigation-case>
<from-outcome>pay</from-outcome>
<to-view-id>/successPay.jsp</to-view-id>
</redirect>
</navigation-case>
</navigation-rule>
I worry about the user using their Back Button or hit Refresh on the browser?
Is my thinking correct or there is an alternative in JSF for these cases
Thanks.
Yes, adding
<redirect/>is one of the right ways to make it a PRG.Other ways involve manually calling
ExternalContext#redirect()in bean action method, or (in JSF 2.x only) addingfaces-redirect=trueparameter to the (implicit navigation) outcome value, which can also be done by a custom configurable navigation handler.