GO
HOME ABOUT POSTS COMMENTS
PRIMEFACES PRIMETECH
← PrimeFaces 1.0.0 and 2.0.0 Released PrimeFaces Event in London →
Recent Posts
Last Post
Porting JSF 2.0′s ViewScope to Spring 3.0 New Infrastructure for [Link]
FEBRUARY 17, 2010 BY CAGATAYCIVICI 7 COMMENTS Dialog Enhancements
If you are using JSF&Spring and decided upgrading to JSF 2.0, one thing you would probably like to have is the JSF TabView Enhancements
2.0′s built-in viewscope. Core Spring doesn’t provide this scope as it is more specific to JSF. No worries, using DataTable Column Resize Callback
Spring’s custom scope feature it is straightforward to port JSF 2.0′s viewscope as a Spring bean scope.
PrimeFaces 3.0.M3 Trailer
01 package [Link]; PrimeFaces Brings Excel to JSF
02
03 import [Link];
Enhanced DataTable Scrolling
04 Be involved in the Spring ROO PrimeFaces add-
05 import [Link];
06 on
07 import [Link];
08 import [Link]; New Timeline
09
10 public class ViewScope implements Scope {
11
12 public Object get(String name, ObjectFactory objectFactory) { @primefaces
13 Map<String,Object> viewMap =
[Link]().getViewRoot().getViewMap(); PrimeFaces Forum reaches 45,000 posts.
14 [Link] 5 days ago
15 if([Link](name)) {
16 return [Link](name); 3.0. Milestone 4 is scheduled on 24th of October.
17 } else {
18 Object object = [Link](); 6 days ago
19 [Link](name, object);
20 1st draft of the User's Guide for 3.0 will be
21 return object; available in early november. Coming soon!
22 } 6 days ago
23 }
24 Looking for the showcase as a downloadable
25 public Object remove(String name) {
26 return [Link]().getViewRoot().getViewMap().remove(name); war? Here it is, updated regularly from
27 } codebase. [Link] 6 days ago
28
29 public String getConversationId() { JavaOne Technical Keynote featured
30 return null;
31 } #PrimeFaces for 2nd consecutive year. "JavaEE
32 PaaS using GlassFish 4.0" [Link]
33 public void registerDestructionCallback(String name, Runnable callback) { #javaone11 1 week ago
34 //Not supported
35 } PrimeFaces is 10% luck, 15% js, 15% css, 20%
36
37 public Object resolveContextualObject(String key) { java, 10% skill, 20% pain, 10% pleasure and
38 return null; 100% PASSION. [Link]
39 }
40 } 1 week ago
Slides of PrimeFaces Talk in Istanbul last
And register this scope in Spring configuration;
weekend are now available. [Link]
2 weeks ago
1 <bean class="[Link]">
2 <property name="scopes"> Introducing OrderList. [Link]
3 <map>
4 <entry key="view"> 3 weeks ago
5 <bean class="[Link]"/>
6 </entry>
Ever wondered who the guys behind
7 </map> PrimeFaces are? [Link]
8 </property> 3 weeks ago
9 </bean>
PrimeFaces Forum reached 44000 posts.
That’s it, now you can use ViewScope for JSF beans that are managed by Spring. As an example to test,
[Link] 3 weeks ago
assume there’s a simple counter page, each click increments the counter, as long as you stay on the same page,
counter state is preserved but when you leave the page the counter is destroyed. If you access counter page again, primefaces
counter will be reset.
01 package [Link];
02
03 import [Link];
04 import [Link];
converted by [Link]
05
06 @Component
07 @Scope("view")
08 public class CounterBean {
09
10 private int counter = 0;
11
12 public int getCounter() {
13 return counter;
14 }
15 public void setCounter(int counter) {
16 [Link] = counter;
17 }
18
19 public void increment() {
20 counter++;
21 }
22 }
1 <h:form>
2 <h:outputText id="counter" value="#{[Link]}" />
3
4 <p:commandButton value="Count" actionListener="#{[Link]}" update="counter"/>
5 </h:form>
By making JSF2′s ViewScope as an available scope to your Spring powered JSF backing beans, you can still take
advantage of Spring Container and at the same time have this very handy scope. Similary FlashScope can be
ported as well.
Share this:
Like this: One blogger likes this post.
FILED UNDER DEVELOPER, JAVA, PRIMEFACES
7 Responses to Porting JSF 2.0′s ViewScope to Spring 3.0
rainwebs says:
February 17, 2010 at 9:37 am
Cool. Will you implement a complete implementation for the community?
cagataycivici says:
February 17, 2010 at 9:39 am
Hi Rainer,
Do you mean implementation of flash scope?
Turjakas says:
February 18, 2010 at 2:22 pm
You did not implement support for destruction callbacks, which in my opinion is quite important to handle the
lifecycle of the Spring beans properly.
I’ve implemented a similar Spring integration to JSF 2.0 ViewScope and I also implemented a proof-of-concept
support for destruction callbacks by storing the callbacks in a map, which uses a combination of session ID
and JSF view ID (filename) as the map key. This is needed to uniquely identify the view to run the correct
destruction callbacks. I’m just wondering whether there is a better way to implement destruction callback
support.
Then I register the Spring scope implementation as a listener to PreDestroyViewMapEvent system event and
get the session and view ID from FacesContext as the event gets fired. The only weird thing seems to be related
to page reloads, which trigger creation of new JSF view scope instance, but it does not fire the
PreDestroyViewMapEvent, so this might cause some sort of memory leaks because of callbacks getting stored
in the map. Any subsequent POST request will cause the event to be fired, however.
I’d also like to see an implementation of Flash scope with ideas of supporting destruction callbacks for it.
In addition to that, have you thought about implementing support for custom conversation/flow scope that could
be controlled in some easy and clean way by the application?
converted by [Link]
rainwebs says:
February 18, 2010 at 8:49 pm
I did not have a look at all the JSF 2 details. But, it seems to me that there’s more to implement to have full
support for all JSF 2 features in Spring. Maybe you have time to complete what you already started .
cagataycivici says:
February 18, 2010 at 8:54 pm
Time? That is something I don’t have But yes, why not.
rainwebs says:
February 18, 2010 at 11:20 pm
Great.
John says:
February 23, 2010 at 8:22 pm
Looks like great info)))) Add to bookmarks. Thanks.
Blog at [Link]. Theme: Enterprise by StudioPress.
Follow
converted by [Link]