Monday, December 2, 2013

Preferred Scope for UIComponent bindings

ADF Faces has the feature of binding a UI component with a reference in the managed bean by setting the binding attribute of the component in UI code.

E.g. 
<af:selectBooleanCheckbox label="Select" id="sbc1"   binding="#{managedBean.checkBox}"/> 

Here, the scope of managedBean is very important. Logically speaking, since a UI component is available on a page only until it lasts. Once the page is transitioned, the component in the previous page shouldn't be there and has to be garbage collected. In such scenario, if we are referring the UI component by a reference sitting in a managed bean defined at scope higher than the View scope, it can't be garbage collected thereby increasing the memory footprint. So to avoid this, we need to refer the UI component only from managed beans at scopes - View/Request/Backingbean. The request scope and backingbean scope is justified because it lasts until the page is transitioned and response is sent back to client and often we need to execute some logic in the code behind with the help of UI component reference.

Suppose you have a taskflow that has only one page in it. Can you now use the reference in managed bean defined at taskflow scope to bind the UI components in the only page of that taskflow. Well, from memory management perspective its okay as the pageflow scope here is almost equal to backingBean scope or requestScope because a page transition here will always lead to exit of the current taskflow thereby clearing the pageflow scope. But still this is not acceptable. Lets see why it is so.
 
When your application works in a cluster environment in the high-availability mode (actually, this is not the only case) the session with all memory scopes higher than request might be serialized in order to be restored on a different JVM instance. UIComponent (The super class of all ADF/JSF Components)  is not a serializable class, and you are going to get a serialization exception in case of binding components to the long-living managed beans.

So, in a nutshell, the preferred scopes for UI component bindings are - View Scope/BackingBean/RequestScope.

1 comment:

  1. Did you hear there is a 12 word sentence you can tell your crush... that will induce intense feelings of love and impulsive attractiveness to you deep within his heart?

    Because hidden in these 12 words is a "secret signal" that triggers a man's instinct to love, adore and look after you with his entire heart...

    12 Words Who Fuel A Man's Desire Impulse

    This instinct is so built-in to a man's brain that it will make him try better than ever before to do his best at looking after your relationship.

    Matter of fact, triggering this mighty instinct is so essential to getting the best ever relationship with your man that as soon as you send your man one of these "Secret Signals"...

    ...You'll soon find him open his soul and heart for you in such a way he's never experienced before and he will distinguish you as the one and only woman in the world who has ever truly fascinated him.

    ReplyDelete