How we're going to fix JSF state saving
State is not bad. Statelesness is not good. State is your friend. But like a bad friend, State can sometimes hang around the house, eating your Mitchell's ice cream and drinking your Amarula 'til he gets fat and lazy, turns your house into a pig sty, and makes you wonder why you ever were friends with him in the first place.
JSF state is kind of like that. As I've said in a previous post, JSF state saving is way too hefty and saves far too much that doesn't need to be saved in the first place. So, here's my 5 step plan for fixing that.
1. Use Facelets.
2. Enhance the ADF Faces
3. Update the ADF Faces Facelets TagHandlers to call
4. Implement Jacob Hookom's idea to save the tree of component state in a Map, not a gigantic Object array hierarchy.
5. Rewrite the Facelets restoreView() implementation to recreate the tree from scratch in its original state, then call restoreState() on each component from the Map we built up in step 4.
And done. You don't need to save the tree structure anymore - Facelets is handling that by recreating the tree from its cached TagHandlers. And since most components don't actually change - unless you explicitly set properties on them - most components don't have to save any state.
(P.S.: there's some trickiness here that I'm ignoring: if you add components dynamically to the hierarchy, you do have to save their state and structure, since it's not present in the page. That's one reason why I strongly recommend making all dynamically created components transient if you have any choice in the matter, but that's a subject for another post.)
JSF state is kind of like that. As I've said in a previous post, JSF state saving is way too hefty and saves far too much that doesn't need to be saved in the first place. So, here's my 5 step plan for fixing that.
Step 1
1. Use Facelets.
Step 2
2. Enhance the ADF Faces
FacesBean API to support a "delta" mode - call a new markInitialState() method on it, and its saveState() implementation only saves all the changes made since markInitialState(). And if there's no changes, just return null. (You can't easily do this without FacesBean; see my earlier post on the subject.) Step 3
3. Update the ADF Faces Facelets TagHandlers to call
markInitialState() after creating the components.Step 4
4. Implement Jacob Hookom's idea to save the tree of component state in a Map, not a gigantic Object array hierarchy.
Step 5
5. Rewrite the Facelets restoreView() implementation to recreate the tree from scratch in its original state, then call restoreState() on each component from the Map we built up in step 4.
And done. You don't need to save the tree structure anymore - Facelets is handling that by recreating the tree from its cached TagHandlers. And since most components don't actually change - unless you explicitly set properties on them - most components don't have to save any state.
(P.S.: there's some trickiness here that I'm ignoring: if you add components dynamically to the hierarchy, you do have to save their state and structure, since it's not present in the page. That's one reason why I strongly recommend making all dynamically created components transient if you have any choice in the matter, but that's a subject for another post.)

24 Comments:
Adam,
It's nice to see you pushing this effort forward. Before I read your blog I posted on one of Jacob Hookom's blog regarding redoing how state is saved and its potential impact on UIData.
http://weblogs.java.net/blog/jhook/archive/2006/01/experiment_goin_1.html
In my post I was assuming state saving could move to more of an approach similar to the one you describe here where the view provides a default version of a view's tree. Which would then allow components to simply store delta's of the base tree. This would also free up the processRestore and processSaveState to actually be used for saving and restoring state.
How does this apply to UIData? Well, since components would only be storing the delta of default data perhaps this would allow for UIData to store full state of all its children components for each iteration with very little increase in data stored instead of only storing EditableValueHolder values. UIData could use the standard state saving and restoring methods of the component tree to manage its children. UIData no longer becomes a special case in the component tree. It simply manages the processing of its children a little differently than UIComponentBase would but in a much cleaner and problem free way.
I believe these changes to UIData would solve any problem I've ever had with it. Hopefully eventually the EG will catch on to your work here.
Mike
By
Mike Youngstrom, at 8:10 AM
I don't necessarily care for the delta approach, it's a patch. I think all components should be request scoped and then take a portlet approach or do the Map thing to only maintain niche conditions. For Seam, it may just want to store a simple key. For the cases that Adam consistently brings up to me, fine store a boolean switch or an int value. But there's no need for us to continue the sharade of storing everything under the sky, knowing very well that we can just replecate the tree on the next request and then apply the state stored in the map-- goodbye tree, goodbye transient parent issues, goodbye huge state objects...
By
Jacob Hookom, at 11:12 PM
just replecate the tree on the next request and then apply the state stored in the map-- goodbye tree, goodbye transient parent issues, goodbye huge state objects...
Jacob:
I'm curious about the "apply the state stored in the map" portion of your proposal? Can you provide a brief idea of how this would work or point me to some place you may have already expounded this? Would parents have any control over their children's state or would the state restoration process be completely flat and centrally managed by some StateManager? How would something like UIData function in this environment? Because the view would be mostly stateless would an approachmore like c:forEach's approach for handling many rows of components be used instead of something like UIData?
Mike
By
Mike Youngstrom, at 1:46 PM
just replecate the tree on the next request and then apply the state stored in the map-- goodbye tree, goodbye transient parent issues, goodbye huge state objects...
Jacob:
I'm curious about the "apply the state stored in the map" portion of your proposal? Can you provide a brief idea of how this would work or point me to some place you may have already expounded this? Would parents have any control over their children's state or would the state restoration process be completely flat and centrally managed by some StateManager? How would something like UIData function in this environment? Or do you think because the view would be mostly stateless would an approach more like c:forEach's be used for handling many rows of components instead of the approach UIData is using?
Mike
By
Mike Youngstrom, at 1:49 PM
oops sorry for the double post.
By
Mike Youngstrom, at 1:50 PM
https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=157
By
Jacob Hookom, at 2:10 PM
Hi,
This is really a nice post, you share good piece of information.
Dissertation Help
By
writeunlimited, at 3:00 AM
Hi,
It’s an interesting article. Thanks for sharing.
Buy Essay
By
uk9876, at 4:57 AM
Hi,
I appreciate the information, well thought out and written. Thank you
GCSE coursework
By
ccw, at 4:59 AM
Hi,
You made some good points there. I did a search on the topic and found most people will agree with your blog. Thanks
Buy Essay
By
se, at 3:15 AM
I truly enjoyed reading it. Waiting for some more great articles like this from you in the coming days
Buy Term Papers
By
Buy Term Paper, at 11:47 PM
Nice blog .. I never thought that you going to write about it:) thanks a lot
buy viagra
generic viagra
By
viagra online, at 7:30 AM
thanks for all!!!
retirement homes in costa rica
By
retirement homes in costa rica, at 1:58 PM
As essay example this writing has a seccess!
By
Larah, at 6:40 AM
http://www.bestpenisproducts.com is an all-natural Penis Enlargement, safe, and guaranteed alternative to painful and dangerous Penis enlargement methods such as surgery, straps, or rings.
penis enlargement pills or male enhancement pills will immediately boost your performance, improve your orgasms, and increase the size of your penis within just a few weeks!
VISIT OUR BEST PENIS ENLARGEMENT PILLS PRODUCTS:
VIGRX PLUS PILLS
VIMAX PILLS
MALE EXTRA PILLS
MALE ENHANCEMENT PILLS
By
Penis Enlargement Pills, at 7:42 AM
We just wanted to share information about best penis enlargement that are busy talking about people who want a bigger penis size, stronger and able to increase stamina.
http://www.sizepenisenlargement.com
Penis Enlargement Pills
Top Penis Enlargement Pills
Method Penis Enlargement Pills
By
best penis enlargement, at 11:58 PM
Very nice blog, is really interesting and fabulous
Really nice!!!
By
eco travel agency costa rica, at 5:35 PM
wow all those garments are so amazing and fabulous I don't come to your blog as often as I would like, but whenever I do I see some really amazing things keep up the good work! =)louis vuitton hobo bags
louis vuitton knockoff bags
louis vuitton man bags
By
louis vuitton bags on sale, at 12:11 AM
I passionately acknowledge that the expertise provided is related to everybody . Thank you .
coral springs fl locksmith
Locksmith Bayonne
Locksmith Cupertino CA
Locksmith Fremont CA
Locksmith Fremont CA
Locksmith Fremont
Locksmith Fremont CA
hialeah locksmith
hialeah locksmiths
hialeah locksmiths
plano tx locksmith
plano tx locksmith
hialeah locksmith
hialeah locksmith
plano tx locksmith
miami beach fl locksmith
mesquite locksmith
miami locksmiths
locksmith irvine ca
miami locksmiths
miami beach fl locksmith
miami beach fl locksmith
By
Anonymous, at 1:03 AM
Hey, very nice website. I actually came across this on Google, and I am happy I did. I will definately be revisiting here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment.
Vimax pills reviews
By
Vimax pills reviews, at 5:20 AM
The 1995 model was extremely popular Nike Outlets for a long time and saw many colors introduced. 2011 Cheap Nike Air Max Online Store Its popularity has waned, but many people still love the shoe. Originally it was met with some skepticism due to its suede construction, UGG Outlet Store. high price tag and neon accent color. International collectors quickly came to love the Air Max 2011 shoe and eventually it became popular in the United States as well.
By
abercrombiefitch, at 8:26 PM
This Nike soccer cleats ultra vibrant New nike soccer shoes ...The Nike soccer cleats has a huge army of fans across the globe, and if you're one of them we know you love them to be bright, flashy and in-your-face colours. Checking out these nike mercurial vapor superfly III fg versions, part of Nike's Fall seasonal releases, we're sure you're going to love these Nike Football Cleats too, they combine Laser technology and Nike Mercurial Vapor Superfly with the Vapor series!especially once they start appearing en masse on pitch. You can click "VIEW MORE" for more detailed pictures. New levels of performance after nike mercurial vapor superfly III new levels of performance after.
By
Nike soccer cleats, at 4:46 PM
I really liked your article.
By
sex bondage video, at 1:01 AM
Thanks for the great post
By
yuna pages, at 10:34 AM
Its really a great tutorial and as I am using these concepts for my project so please do keep posting more on JSF.
By
compare motor trade insurance, at 6:23 AM
Post a Comment
Links to this post:
Create a Link
<< Home