开发者

Implementing PRG on JSF

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 some开发者_如何学Pythonthing 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) adding faces-redirect=true parameter to the (implicit navigation) outcome value, which can also be done by a custom configurable navigation handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜