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

10 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 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 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 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 Anonymous Mike Youngstrom, at 1:49 PM  

  • oops sorry for the double post.

    By Anonymous Mike Youngstrom, 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,
    This is really a nice post, you share good piece of information.

    Dissertation Help

    By Blogger writeunlimited, at 3:00 AM  

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


    Buy Essay

    By Blogger uk9876, at 4:57 AM  

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

    GCSE coursework

    By Blogger 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 Blogger se, at 3:15 AM  

Post a Comment

Links to this post:

Create a Link

<< Home