Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
titleStateful.java
interface Stateful {

public voidObject saveStategetState(Page) page,{
 Context context)
// public void saveState(Page page, Context context, Map options)??
  // By default save in session under its name+page path
 // This method can call getState to retrieve this components state
  // Optimization includes GZIP Assemble state and return as object. This allows developers to save state in cookie instead.
// It also allows parent containers to assemble its children state recursively
// If this control is a container it should assemble all its child control state.
}

public void setState(Object state) {
    // Cast object back to its type and set state to this control and its children
}

Some useful utilities include:

Code Block
titleClickUtils.java

public static void saveState(Stateful stateful compressing the state


public void restoreState(Page page, Context context) {
// public static void restoreStatesaveState(PageStateful pagestateful, Context context, Map options)??
  // By default Grabsave state fromin session and invoke setState

public Object getState() {
  in a map that is stored against the request page path
 // AssembleThis statemethod andcan returncall as objectstateful.getState Thisto allowsretrieve developersthis tocomponents save state
 in cookie instead.
// IfOptimization thisincludes controlGZIP is a container it should assemble all its child control state.
}compressing the state


public static void setState(Object staterestoreState(Stateful stateful, Context context) {
    //public static Castvoid object back to its type and setrestoreState(Context context, Map options)??
  // Grab state tofrom thissession control and itsinvoke children
}

public String getStateFormatted() {
  // Return a user friendly presentation of the state
}
stateful.setState
}

Each control will be responsible for storing it's own state as well as it's children. It's up to the control or container how to best store the state, but should keep the following in mind:

  • state stored in the session is replicated in a cluster and should be as compact as possible eg: object array instead of a List
  • while arrays are compact and has order, child controls can be reordered meaning the wrong state could be applied to a control. In this instance a Map would be a more flexible solution by storing the control state against its name, and structural order doesn't matter, as long as the controls are moved around inside that container only. If a control is moved to another container it won't be possible to restore it's state automatically, however it would still be possible for the developer to find the original state and apply it manually on the changed structure.