JSF 2 provides copule of new scopes, among which the "Flash" scope is quite interesting. (i believe the concept is borrowed from other frameworks like the "Stripes" framework)
this is quoted from the Stripes framework documentation of its class net.sourceforge.stripes.controller.FlashScope:
[quote]
A FlashScope is an object that can be used to store objects and make them available as request parameters during this request cycle and the next one. It is extremely useful when implementing the redirect-after-post pattern in which an ActionBean receives a POST, does some processing and then redirects to a JSP to display the outcome. FlashScopes make temporary use of session to store themselves briefly between two requests.
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/FlashScope.html
[/quote]
The Flash scope could be used for a redirection to show outcomes after a insertion and/or update of entities. Since it's a redirect, instead of the default "forward"; at the server sider, all @RequestScoped variables will be reinitialized and thus would lose values. However, it's often desirable to keep those varaibles available to the "next" page. The new Flash scope fills this gap.
API example:
this is quoted from the Stripes framework documentation of its class net.sourceforge.stripes.controller.FlashScope:
[quote]
A FlashScope is an object that can be used to store objects and make them available as request parameters during this request cycle and the next one. It is extremely useful when implementing the redirect-after-post pattern in which an ActionBean receives a POST, does some processing and then redirects to a JSP to display the outcome. FlashScopes make temporary use of session to store themselves briefly between two requests.
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/controller/FlashScope.html
[/quote]
The Flash scope could be used for a redirection to show outcomes after a insertion and/or update of entities. Since it's a redirect, instead of the default "forward"; at the server sider, all @RequestScoped variables will be reinitialized and thus would lose values. However, it's often desirable to keep those varaibles available to the "next" page. The new Flash scope fills this gap.
API example:
ExternalContext cntxt = FacesContext.getCurrentInstance().getExternalContext();
// lets set logged in user into to "flash" scope.
// 1. it can be accessed like this: "#{flash.USER-key.username}"; in the JSF2 pages.
// 2. or in the backing bean code: User user = (User) flash.get("USER-key");
Flash flash = cntxt.getFlash();
flash.put("USER-key", this.user);
本文深入探讨了JSF2框架中的FlashScope概念及其应用,特别是在实现插入和更新实体后的重定向模式中。通过实例展示了如何在JSF2页面中访问和设置FlashScope变量,并解释了其与常规请求作用域的区别。
3112

被折叠的 条评论
为什么被折叠?



