myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randahl Fink Isaksen <>
Subject Re: How to saveState / restoreState for properties that have value bindings
Date Wed, 18 Oct 2006 14:58:53 GMT
Actually I finally found an example on the web in which the restoreState 
method actually takes responsibility of restoring the value bindings 
internal state (see below) - can anyone confirm that this is the right 
approach for properties with value bindings?


public Object saveState(FacesContext context) {
  Object values[] = new Object[2];
  values[0] = super.saveState(context);
  values[1] = getValue();
  return values;

public void restoreState(FacesContext context, Object state) {
  Object values[] = (Object[]) state;
  super.restoreState(context, values[0]);
  Object savedValue = values[1];
  ValueBinding vb = getValueBinding("value");
  if (vb != null) {
  vb.setValue(context, savedValue);

Randahl Fink Isaksen wrote:
> I have been looking through a number of MyFaces components to see how 
> state saving was implemented, and it turns out that all the components 
> I have checked simply implement the saveState and restoreState methods 
> by returning an Object[] containing their private properties.
> But I keep asking myself "what about value bound properties?" If I 
> have a component which has a property X which may be bound to 
> #{someBean.someProperty} does that not mean that I need to restore the 
> value of the value binding?
> I would expect that restoreState should check if X was bound with a 
> value binding and then restore the value of the value binding instead. 
> Could anyone please elaborate? Thanks.
> Randahl

View raw message