net.jspcontrols.wizard.impl
Class Wizard

java.lang.Object
  extended bynet.jspcontrols.wizard.impl.Wizard
All Implemented Interfaces:
IWizard
Direct Known Subclasses:
SignupWizard

public class Wizard
extends java.lang.Object
implements IWizard

This class containts base implementation of wizard controller and handles wizard traversal. The wizard controller contains references to wizard states and transitions, and allows to move from one state to another.

The UI specifics like reporting of error messages should be handled by descendant classes.


Field Summary
protected  IWizardStep currentState
          Current state of this wizard.
protected  java.util.Map errors
          Error list.
protected  java.util.Map listeners
          Listeners, checking for state transition
protected  IWizardStep sourceState
          The intial state of this wizard.
 
Constructor Summary
Wizard()
           
 
Method Summary
 void addListener(IWizardListener listener)
          Adds a listener for state change event.
 boolean back()
          Tries to move to the previous state.
protected  boolean canLeave(int event)
          Executed after the forward transition is chosen, but before the state is changed.
 void clearWizardErrors()
          Clear wizard errors.
static IWizardStep findNode(IWizardStep state, java.lang.String name)
          Finds a state by its name.
 boolean forward()
          Tries to move to the next state.
 IWizardStep getCurrentStep()
          Returns current state of this wizard; on wizard startup is the same as source state.
 java.lang.String getCurrentStepName()
          Returns a name which is used to display proper wizard panel.
 java.util.Map getListeners()
          Returns all current listeners for wizard event
 IWizardStep getSourceStep()
          Returns source state of this wizard.
 IWizardStep getStepByName(java.lang.String name)
          Locates a state in this wizard by its name
 java.util.Map getWizardErrors()
          Standard implementation returns a dummy map for error messages in case the concrete implementation generates messages externally and does not provide message placeholder.
 boolean isCompleted()
          Returns true if wizard has been successfully completed.
protected  boolean isLastStep()
          Verifies is current wizard step a last step.
 void removeAllListeners()
          Removes all wizard listeners for state change event.
 void removeListener(IWizardListener listener)
          Removes a listener for state change event.
 void wizardReset()
          Resets certain wizard fields, like booleans.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentState

protected IWizardStep currentState
Current state of this wizard.


errors

protected java.util.Map errors
Error list. Key is either string message or ID of a message in a property file. Value is a string array of values, or null if there are no arguments.

Errors are initialized in backing bean when a wizard object is created. Reference to existing error object must be passed to this wizard controller from backing bean.


listeners

protected java.util.Map listeners
Listeners, checking for state transition


sourceState

protected IWizardStep sourceState
The intial state of this wizard. A wizard has only one initial state.

Constructor Detail

Wizard

public Wizard()
Method Detail

addListener

public void addListener(IWizardListener listener)
Adds a listener for state change event.

Specified by:
addListener in interface IWizard

back

public boolean back()
Tries to move to the previous state. Stays on the current state if traversal back is impossible either because this state is the initial wizard state or was marked as checkpoint.

Specified by:
back in interface IWizard
Returns:
true if was able to move to a previous step, false otherwise

canLeave

protected boolean canLeave(int event)
Executed after the forward transition is chosen, but before the state is changed. Verifies with listening application, is it allowed to perform a state change

Parameters:
event - event that is occurring now, like moving to next step
Returns:
true if all listeners allow to move to the next step

clearWizardErrors

public void clearWizardErrors()
Clear wizard errors. Does nothing here (need to implement). Backing bean will clear errors when needed.

Specified by:
clearWizardErrors in interface IWizard

findNode

public static IWizardStep findNode(IWizardStep state,
                                   java.lang.String name)
Finds a state by its name. Need to pass staring state as an argument because of the recursive calls. Starting state parameter allows to search from any state.

Important: starting state itself is not checked

Parameters:
state - the state where to start search, this state itself is not verified and must be checked outside this method
name - the name of the state to look for
Returns:
the state with the needed name, or null if state not found

forward

public boolean forward()
Tries to move to the next state. If cannot move, keeps current state.

Specified by:
forward in interface IWizard
Returns:
true if was able to move to a next step, false otherwise
See Also:
IWizardStep.addOutgoingTransition(IWizardTransition)

getCurrentStep

public IWizardStep getCurrentStep()
Returns current state of this wizard; on wizard startup is the same as source state.

Specified by:
getCurrentStep in interface IWizard
Returns:
current state of this wizard

getCurrentStepName

public java.lang.String getCurrentStepName()
Returns a name which is used to display proper wizard panel.

Specified by:
getCurrentStepName in interface IWizard
Returns:
mapping name for a wizard view, usually path to JSP page

getListeners

public java.util.Map getListeners()
Returns all current listeners for wizard event


getSourceStep

public IWizardStep getSourceStep()
Returns source state of this wizard. A wizard has only one initial state.

Specified by:
getSourceStep in interface IWizard
Returns:
source state of this wizard

getStepByName

public IWizardStep getStepByName(java.lang.String name)
Locates a state in this wizard by its name

Specified by:
getStepByName in interface IWizard
Parameters:
name - state name
Returns:
the first state starting from source, which name is equal to the needed name, or null if the state not found.

getWizardErrors

public java.util.Map getWizardErrors()
Standard implementation returns a dummy map for error messages in case the concrete implementation generates messages externally and does not provide message placeholder.

Concrete implementation must provide a valid reference to message map, if it wants to return messages from Rule Engine.

Specified by:
getWizardErrors in interface IWizard
Returns:
message placeholder map

isCompleted

public boolean isCompleted()
Returns true if wizard has been successfully completed. Wizard is usually completes on its last step, after business accounts is updated. Completed status is retained by the wizard until wizard instance is disposed.

Specified by:
isCompleted in interface IWizard
Returns:
true if wizard has been successfully completed and is ready to be disposed.

isLastStep

protected boolean isLastStep()
Verifies is current wizard step a last step.

Returns:
true if current wizard step a last step

removeAllListeners

public void removeAllListeners()
Removes all wizard listeners for state change event.

Specified by:
removeAllListeners in interface IWizard

removeListener

public void removeListener(IWizardListener listener)
Removes a listener for state change event.

Specified by:
removeListener in interface IWizard

wizardReset

public void wizardReset()
Description copied from interface: IWizard
Resets certain wizard fields, like booleans. Called with every user input. The primary reason for this method is older frameworks like Struts, which use default HTTP handling of boolean properties, and do not notifiy a property when it is cleared.

Specified by:
wizardReset in interface IWizard