1 16 package javax.faces.application; 17 18 import java.io.Serializable ; 19 20 21 25 public abstract class StateManager 26 { 27 public static final String STATE_SAVING_METHOD_PARAM_NAME = "javax.faces.STATE_SAVING_METHOD"; 28 public static final String STATE_SAVING_METHOD_CLIENT = "client"; 29 public static final String STATE_SAVING_METHOD_SERVER = "server"; 30 private Boolean _savingStateInClient = null; 31 32 public abstract StateManager.SerializedView saveSerializedView(javax.faces.context.FacesContext context); 33 34 protected abstract Object getTreeStructureToSave(javax.faces.context.FacesContext context); 35 36 protected abstract Object getComponentStateToSave(javax.faces.context.FacesContext context); 37 38 public abstract void writeState(javax.faces.context.FacesContext context, 39 StateManager.SerializedView state) 40 throws java.io.IOException ; 41 42 public abstract javax.faces.component.UIViewRoot restoreView(javax.faces.context.FacesContext context, 43 String viewId, 44 String renderKitId); 45 46 protected abstract javax.faces.component.UIViewRoot restoreTreeStructure(javax.faces.context.FacesContext context, 47 String viewId, 48 String renderKitId); 49 50 protected abstract void restoreComponentState(javax.faces.context.FacesContext context, 51 javax.faces.component.UIViewRoot viewRoot, 52 String renderKitId); 53 54 public boolean isSavingStateInClient(javax.faces.context.FacesContext context) 55 { 56 if (_savingStateInClient != null) return _savingStateInClient.booleanValue(); 57 String stateSavingMethod = context.getExternalContext().getInitParameter(STATE_SAVING_METHOD_PARAM_NAME); 58 if (stateSavingMethod == null) 59 { 60 _savingStateInClient = Boolean.FALSE; context.getExternalContext().log("No state saving method defined, assuming default server state saving"); 62 } 63 else if (stateSavingMethod.equals(STATE_SAVING_METHOD_CLIENT)) 64 { 65 _savingStateInClient = Boolean.TRUE; 66 } 67 else if (stateSavingMethod.equals(STATE_SAVING_METHOD_SERVER)) 68 { 69 _savingStateInClient = Boolean.FALSE; 70 } 71 else 72 { 73 _savingStateInClient = Boolean.FALSE; context.getExternalContext().log("Illegal state saving method '" + stateSavingMethod + "', default server state saving will be used"); 75 } 76 return _savingStateInClient.booleanValue(); 77 } 78 79 80 public class SerializedView 81 { 82 private Object _structure; 83 private Object _state; 84 85 public SerializedView(Object structure, Object state) 86 { 87 _structure = structure; 88 _state = state; 89 } 90 91 public Object getStructure() 92 { 93 return _structure; 94 } 95 96 public Object getState() 97 { 98 return _state; 99 } 100 } 101 } 102 | Popular Tags |