restoreAttachedState and saveAttachedState

If you had come across a situation where you wanted to restore state of a non-primitive member variable, and found that it was not working, here is the solution:
public void restoreState(FacesContext context, Object state) {
Object[] values = (Object[]) state;
super.restoreState(context, values[0]);

//Don' do this; it will fail on you!!!
//listenerPointers = (Map<String, ArrayList<Class<? extends ActionListener>>>) values[1];

//This will work!!!
listenerPointers = (Map<String, ArrayList<Class<? extends ActionListener>>>) restoreAttachedState(context,values[1]);
}
Notice the call to restoreAttachedState(facesContext, value).

"saveAttachedState(facesContext, value) is the saveState() counter-part.

Both are static methods in UIComponentBase class.

0 comments: