JSF in SF

Thursday, March 02, 2006

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.

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.)

21 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 Anonymous Anonymous, 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 Blogger 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 Anonymous Anonymous, 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 Anonymous Anonymous, at 1:49 PM  

  • oops sorry for the double post.

    By Anonymous Anonymous, at 1:50 PM  

  • https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=157

    By Blogger Jacob Hookom, at 2:10 PM  

  • Hi,
    It’s an interesting article. Thanks for sharing.


    Buy Essay

    By Blogger Unknown, at 4:57 AM  

  • Hi,
    I appreciate the information, well thought out and written. Thank you

    GCSE coursework

    By Blogger Unknown, 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 Blogger Unknown, 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 Anonymous Buy Term Paper, at 11:47 PM  

  • As essay example this writing has a seccess!

    By Blogger Larah, at 6:40 AM  

  • Very nice blog, is really interesting and fabulous
    Really nice!!!

    By Anonymous 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 Anonymous louis vuitton bags on sale, at 12:11 AM  

  • By Anonymous 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 Anonymous Vimax pills reviews, at 5:20 AM  

  • I really liked your article.

    By Anonymous sex bondage video, at 1:01 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 Anonymous compare motor trade insurance, at 6:23 AM  

  • I really love your article, I also love travel China, in my past 5 years I traveled China a lot, see my favorite site
    China Tours adviser and Beijing
    Tour Adviser
    and Xian tour adviser, hope it will help with your China trip.

    By Anonymous China Tours, at 7:56 PM  

  • What a beautiful dragonfly and what wonderful post!!I am a china tour lover,You can learn more: China travel videos, China hotels list by city name, Tours in Beijing City

    By Blogger Unknown, at 7:58 PM  

  • By Blogger for ict 99, at 9:45 PM  

  • Very good post. I share to my friend and other
    If you need jobs here

    By Blogger Boxstrem, at 4:47 PM  

Post a Comment

<< Home