Using OmniFaces 2.1 ViewScoped with Spring 3.1.0 in JSF 2.2

I'm trying to convert some pages to View scope (from Session Scope) to enable multiple browser tabs to support showing data from multiple entries from a datatable.

Does anyone know whether following the steps in this PrimeFaces blog Porting JSF 2.0′s ViewScope to Spring 3.0 will work to extend Spring to use org.omnifaces.cdi.ViewScoped from Omnifaces 2.1?


You can just use the approach described in the blog you found. Only you don't and can't exactly port in such way that it under the covers actually uses the specific @ViewScoped annotation. Basically, you should implement the same code as those annotations are under the covers using.

Both the standard JSF @ViewScoped and the OmniFaces @ViewScoped do under the covers basically the same as descibed in the blog: referencing the bean instances via UIViewRoot#getViewMap() . Only, the JSF 2.0/2.1 @ViewScoped didn't properly trigger @PreDestroy of beans in all cases. Eg they won't be called when the underlying HTTP session expires. OmniFaces had solved those issues for JSF 2.0/2.1 users. JSF itself has solved them in 2.2. So in JSF 2.2 there is not really a reason to use OmniFaces @ViewScoped .

Although I'd like to hint here that I'm for future OmniFaces 2.2 planning to add a beforeunload hook to <o:form> when an OmniFaces @ViewScoped bean is used, so that the bean also really get destroyed when the user navigates away by GET, or refreshes the page, or closes the browser window, making it yet more useful again :)

链接地址: http://www.djcxy.com/p/58692.html

上一篇: 使用jQuery UI在范围滑块中输入错误的值

下一篇: 在JSF 2.2中使用OmniFaces 2.1 ViewScoped和Spring 3.1.0