org.wizard4j.wrapper
Class HtmlWrapper

java.lang.Object
  extended by org.wizard4j.engine.SessionManager
      extended by org.wizard4j.wrapper.HtmlWrapper

public class HtmlWrapper
extends SessionManager

This class provides an html wrapper around the FlowchartSession API. After creating a managed session, an application will receive a html form from the wrapper and it can return a parameter map to obtain the next html form.

An application using the wrapper will typically contain code similar to the following excerpt:

 WizardValidator validator = WizardFactory.newWizardValidator();
 Flowchart flowchart = validator.validateFlowchart(flowchartSource);
 HtmlWrapper htmlWrapper = WizardFactory.newHtmlWrapper(timeout, servletPath, false);
 String flowchartSessionId = htmlWrapper.createManagedSession(flowchart);
 String htmlCode = htmlWrapper.first(flowchartSessionId);
 ...
 

or in case a ticket is used:

 WizardValidator validator = WizardFactory.newWizardValidator();
 Flowchart flowchart = validator.validateFlowchart(flowchartSource);
 HtmlWrapper htmlWrapper = WizardFactory.newHtmlWrapper(timeout, servletPath, true);
 String flowchartSessionId = htmlWrapper.createManagedSession(flowchart);
 String ticket = htmlWrapper.first(flowchartSessionId);
 ...
 String htmlCode = htmlWrapper.getHtml(ticket);
 ...
 

A typical parsing of the user input looks like this:

 String htmlCode = htmlWrapper.request(httpServletRequest.getParameterMap());
 

This method constructs a html table based on the provided FlowchartResponse which has following structure:

 <div id="wizard">
 <table>
   <tr><td><table><tr><td><input class="wizard_button_default"><input class="wizard_button"></td> ... </tr></table></tr><!-- navigation buttons -->
   
   <tr><td><table>
     list of presentations
   </table></td></tr>
  OR 
   <tr><td><table>
     <tr><td colspan="3" class="validation_error">Potential Error Message</td></tr>   
     <tr><td>label1</td><td>input field1</td><td>(help1)</td></tr>
     <tr><td colspan="2">info description</td><td>help</td></tr>
     ...
     <tr><td>labelN</td><td>input fieldN</td><td>(helpN)</td></tr>
     
   </table></td></tr>
   <tr><td><table><tr><td><input class="wizard_button"></td> ... </tr></table></td></tr><!-- progress buttons -->
 </table>
 <div>
 

Note that the form is surrounded by a div with id 'wizard'. There are also a number of classes defined. Both can be used by a custom css to apply a specific layout.


Constructor Summary
HtmlWrapper(int sessionTimeout, java.lang.String servletPath, boolean useTicket)
          Constructor of the HtmlWrapper.
 
Method Summary
 void addPresentationHtml(java.lang.String sessionId, java.lang.String presentationHtml)
          An application can add html fragments to be shown when the flowchart is executed.
 java.lang.String createManagedSession(Flowchart flowchart)
          Create a managed session.
 java.lang.String first(java.lang.String sessionId)
           
 java.lang.String getHtml(java.lang.String ticket)
          Get the html code corresponding to this ticket
 boolean isPostFlowchartHtml()
           
 void putActionLabel(java.lang.String sessionId, EUserAction action, java.lang.String label)
          Change the label of an action button.
 void putHelpLabel(java.lang.String sessionId, java.lang.String helpLabel)
          Change the label of the help button.
 java.lang.String request(java.util.Map<java.lang.String,java.lang.String[]> parameterMap)
           
 void setPostFlowchartHtml(boolean postFlowchartHtml)
          If this parameter is set, the wrapper will return an overview of presentations at the end of the flowchart execution.
 
Methods inherited from class org.wizard4j.engine.SessionManager
cancel, getDefaultGroupType, getResult, getSessionTimeout, index, isDefaultAllowMultipleRatesPerRun, isDefaultAllowMultipleSavesPerRun, isDefaultAutomaticSave, isDefaultKeepStateInResponse, isDefaultMaskCancelAction, isDefaultMaskIndexAction, isDefaultMaskNextAction, isDefaultMaskPreviousAction, isDefaultMaskRateAction, isDefaultMaskSaveAction, isDefaultMaskStartAction, isDefaultMaskStateAction, isDefaultResendResponseAtRequestError, isDefaultResendResponseWithErrorAtParameterError, next, previous, rate, save, setActionMask, setAllowMultipleRatesPerRun, setAllowMultipleSavesPerRun, setAutomaticSave, setDefaultAllowMultipleRatesPerRun, setDefaultAllowMultipleSavesPerRun, setDefaultAutomaticSave, setDefaultGroupType, setDefaultKeepStateInResponse, setDefaultMaskCancelAction, setDefaultMaskIndexAction, setDefaultMaskNextAction, setDefaultMaskPreviousAction, setDefaultMaskRateAction, setDefaultMaskSaveAction, setDefaultMaskStartAction, setDefaultMaskStateAction, setDefaultResendResponseAtRequestError, setDefaultResendResponseWithErrorAtParameterError, setFlowchartMonitor, setGroupType, setResendResponseAtRequestError, setResendResponseWithErrorAtParameterError, setStoreStateInResponse, start, state
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlWrapper

public HtmlWrapper(int sessionTimeout,
                   java.lang.String servletPath,
                   boolean useTicket)
Constructor of the HtmlWrapper.

Parameters:
sessionTimeout - time after which an inactive session is removed
servletPath - the servlet which will handle the form submission
useTicket - when true the methods first(String) and request(Map) return a ticket instead of the html code. This is useful in case one wants to do a http redirect after the form submission. With the ticket the html code can be obtained later on with getHtml(String).
Method Detail

createManagedSession

public java.lang.String createManagedSession(Flowchart flowchart)
Create a managed session.

Parameters:
flowchart -
Returns:
flowchart sessionId

getHtml

public java.lang.String getHtml(java.lang.String ticket)
                         throws NonExistingSessionException
Get the html code corresponding to this ticket

Parameters:
ticket -
Returns:
html code
Throws:
NonExistingSessionException - if session does not exist anymore

first

public java.lang.String first(java.lang.String sessionId)
                       throws NonExistingSessionException,
                              UnexpectedRequestException
Parameters:
sessionId -
Returns:
ticket or html code
Throws:
NonExistingSessionException
UnexpectedRequestException

request

public java.lang.String request(java.util.Map<java.lang.String,java.lang.String[]> parameterMap)
                         throws NonExistingSessionException,
                                UnexpectedRequestException,
                                InvalidValueException
Parameters:
parameterMap -
Returns:
ticket or html code
Throws:
NonExistingSessionException
UnexpectedRequestException
InvalidValueException

isPostFlowchartHtml

public boolean isPostFlowchartHtml()
Returns:
true/false

setPostFlowchartHtml

public void setPostFlowchartHtml(boolean postFlowchartHtml)
If this parameter is set, the wrapper will return an overview of presentations at the end of the flowchart execution. Which presentations are shown is controlled by the application developer via addPresentationHtml(String, String).

Parameters:
postFlowchartHtml -

addPresentationHtml

public void addPresentationHtml(java.lang.String sessionId,
                                java.lang.String presentationHtml)
An application can add html fragments to be shown when the flowchart is executed. Typically one will add a fragment for each presentation that one wants to offer to the user, and typically again this will be a link to the output obtained by applying the flowchart result to the presentation/template.

Parameters:
sessionId -
presentationHtml -

putHelpLabel

public void putHelpLabel(java.lang.String sessionId,
                         java.lang.String helpLabel)
Change the label of the help button.

Parameters:
sessionId -
helpLabel -

putActionLabel

public void putActionLabel(java.lang.String sessionId,
                           EUserAction action,
                           java.lang.String label)
Change the label of an action button.

Parameters:
sessionId -
action -
label -