Implementation: org.glassfish 2.2.12
I have the following session-scoped validator:
@ManagedBean
@SessionScoped
public class CreateGroupNameValidator extends LengthValidator implements Serializable{
@ManagedProperty(value="#{myDao}")
private MyDao myDao;
//Validate methods
}
In spite of being session-scoped and Serializable
, the validator fails to restore the value of the property myDao
when postback comes. I used debugger and figuredOut that the state is saved by the class StateHolderSaver
which has the following consturctor:
public StateHolderSaver(FacesContext context, Object toSave) {
className = toSave.getClass().getName();
if (toSave instanceof StateHolder) {
// do not save an attached object that is marked transient.
if (!((StateHolder) toSave).isTransient()) {
Serializable [] tuple = new Serializable[StateHolderTupleIndices.LastMember.ordinal()];
tuple[StateHolderTupleIndices.StateHolderSaverInstance.ordinal()] =
(Serializable) ((StateHolder) toSave).saveState(context);
if (toSave instanceof UIComponent) {
tuple[StateHolderTupleIndices.ComponentAddedDynamically.ordinal()] = ((UIComponent)toSave).getAttributes().containsKey(DYNAMIC_COMPONENT) ? Boolean.TRUE : Boolean.FALSE;
}
savedState = tuple;
} else {
className = null;
}
} else if (toSave instanceof Serializable) {
savedState = (Serializable) toSave;
className = null;
}
}
So, since LenghtValidator
implements javax.faces.component.StateHolder
it didn't save my initial Dao value. Is it a normal behavior?