Show TOC

Step 2: Creating the Wizard ComponentLocate this document in the navigation structure

Context

Each wizard contains a wizard component, whose Java class extends AbstractWizard . This class is descended from AbstractPortalComponent , making the wizard a standard iView that can be displayed in the portal administration pages.

AbstractWizard requires you to implement one method, setupWizard() , which is passed an IConfigurableWizard object. In this method, the wizard does the following:

  • Sets the wizard title.

  • Adds panes to the IConfigurableWizard object

  • Sets the transitions between panes.

  • Sets dependencies between data model objects.

Procedure


  1. Create a new class that extends AbstractWizard .

  2. Implement setupWizard() , which has the following signature:

    public void setupWizard(
        com.sapportals.admin.wizardframework.api.IConfigurableWizard wizard,
        IPortalComponentProfile profile,
        java.util.Map params,
        java.util.ResourceBundle bundle) {
     
    }
    
                         

    The method receives an IConfigurableWizard object, which is used to create panes, add transitions, and add dependencies.

    In this method, do the following:

    • Create Panes: To create and add a pane to the wizard, supply a key for the pane and the pane's class name, as shown in the following example:

      wizard.addPane(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY,
          PersonalDetailsPane.class.getName());
                                 
    • Add Transitions: Transitions determine to what panes the wizard navigates when each button is clicked.

      Note

      You only need transitions if the wizard is not a linear set of panes. If no transitions are created, the wizard navigates from pane to pane in the order they were added to the wizard.

      The following enables the Next button when the address pane is displayed, and specifies that the wizard display the table pane when the button is clicked:

      wizard.addTransition(AddressPane.ADDRESS_PANE_KEY,
          NEXT, null, TablePane.TV_PANE_KEY);
                                 

      Each transition can also contain a condition that must return true in order for the transition to take effect. If the condition is false , the navigation specified by the transition does not take place.

      A condition is an instance of a class that extends ICondition . For more information, see Step 3: Creating Conditions .

      The following is an example of a transition with a condition:

      wizard.addTransition(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY,
          NEXT, stuCond, StudentPane.STUDENT_PANE_KEY);
                                 
    • Add Dependencies: Dependencies cause objects in the data model to be deleted whenever the value of other objects change. For example, you may want to clear the address field if the administrator changes the name field.

      The following clears all properties that start with the address pane key if the last name in the personal details pane was changed:

      wizard.addDependency(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY
          +".last_name", AddressPane.ADDRESS_PANE_KEY);
                                 
  3. Create a <component> element in the portalapp.xml for the wizard component, similar to the element for a standard component.

    Add a property element called isStateless in the <component-profile> element called to determine if session data is maintained on the client ( true ) or on the server ( false ).

    <components>
        <component name="trainSample">
            <component-config>
                <property name="ClassName" value="TrainWizard"/>
                <property name="LocalModeAllowed" value="true"/>
                <property name="SafetyLevel" value="low_safety"/>
            </component-config>
            <component-profile>
                <property name="isStateless" value="true"/>
            </component-profile>
        </component>
    </components>
    
                         

Results

The following is an example of setupWizard() that creates:

  • 6 panes

  • A close pane that closes the wizard

  • A condition ( isStudent )

  • Several transitions that define how the wizard navigates between panes

  • One data dependency

public void setupWizard(
   com.sapportals.admin.wizardframework.api.IConfigurableWizard wizard,
   IPortalComponentProfile profile,
   java.util.Map params,
   java.util.ResourceBundle bundle) {
 
    wizard.setTitle("Order Train Tickets");
      
    wizard.addPane(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY,
        PersonalDetailsPane.class.getName());
    wizard.addPane(AddressPane.ADDRESS_PANE_KEY,
        AddressPane.class.getName());
    wizard.addPane(StudentPane.STUDENT_PANE_KEY,
        StudentPane.class.getName());
 
    wizard.addPane("close",com.sapportals.admin.wizardframework.
        components.CloseWizardComponent.class.getName());
    wizard.addPane(TicketInfo.TICKET_INFO_PANE_KEY,
        TicketInfo.class.getName());
    wizard.addPane(ShowPanes.SHOW_PANE_KEY, ShowPanes.class.getName());
    wizard.addPane(TablePane.TV_PANE_KEY, TablePane.class.getName());
 
//creating an instance of the ICondition, IsStudent
    IsStudent stuCond = new IsStudent();
 
//creating the reverse condition from IsStudent
    ICondition notStuCond = new IsStudent() {
        public boolean isTrue(IWizardContext ctx) {
            return !super.isTrue(ctx);
        }
    };
      
    wizard.addTransition(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY,
        NEXT, stuCond, StudentPane.STUDENT_PANE_KEY);
    wizard.addTransition(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY,
        NEXT, notStuCond, AddressPane.ADDRESS_PANE_KEY);
 
    wizard.addTransition(AddressPane.ADDRESS_PANE_KEY, BACK, stuCond,
        StudentPane.STUDENT_PANE_KEY);
    wizard.addTransition(AddressPane.ADDRESS_PANE_KEY, BACK,   
        notStuCond,PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY);
 
    wizard.addTransition(StudentPane.STUDENT_PANE_KEY, BACK, null,
        PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY);
    wizard.addTransition(StudentPane.STUDENT_PANE_KEY, NEXT, null,
        AddressPane.ADDRESS_PANE_KEY);
 
    wizard.addTransition(AddressPane.ADDRESS_PANE_KEY, NEXT, null,
        TablePane.TV_PANE_KEY);
    wizard.addTransition(TicketInfo.TICKET_INFO_PANE_KEY, BACK, null,
        AddressPane.ADDRESS_PANE_KEY);
 
    wizard.addTransition(TicketInfo.TICKET_INFO_PANE_KEY, NEXT, null,
        TablePane.TV_PANE_KEY);
 
    wizard.addTransition(TablePane.TV_PANE_KEY, NEXT, null,
        ShowPanes.SHOW_PANE_KEY);
    wizard.addTransition(TablePane.TV_PANE_KEY, BACK, null,
        AddressPane.ADDRESS_PANE_KEY);
 
    wizard.addTransition(ShowPanes.SHOW_PANE_KEY, FINISH, null,
        "close");
    wizard.addTransition(ShowPanes.SHOW_PANE_KEY, BACK, null,
        TablePane.TV_PANE_KEY);
 
    wizard.addDependency(PersonalDetailsPane.PERSONAL_DETAILS_PANE_KEY
        +".last_name", AddressPane.ADDRESS_PANE_KEY);
}