Portlet Factory, Version 6.1.2


 

About implementing a coordinator

The coordinator class allows you to dynamically modify the builder call editor for your builder depending on the value of an input.

When you change a value in the builder call editor, the coordinator handles that event with a processChange() method. In the processChange() method, you can determine which input changed and perform one or more of the following actions:

  • Hide displayed inputs.

  • Display inputs previously not displayed.

  • Add inputs dynamically.

  • Implement any other desired functionality with Java code.

The following Java code implements a coordinator that displays two additional inputs when a particular check box is enabled in the builder call editor.

package com.bowstreet.examples.builders.webapp; import com.bowstreet.editor.uitools.coordinator.WebAppBaseCoordinator; import com.bowstreet.generation.DynamicBuilderInputDefinition; import com.bowstreet.generation.BuilderInputDefinition; import java.util.Iterator;
public class APITestCoordinator extends WebAppBaseCoordinator {
  public String initializeInputs(boolean isNewBuilderCall) {
     if(isNewBuilderCall) {
        /*Perform initialization for new builder calls.
          For example, you can set initial values for an input:
          context.findInputDefinition("CustomerName").setString("Marla");
        */
     }
     //Determine whether to mark some inputs as visible or not
     if(context.findInputDefinition("ShowMoreInputs").getBoolean()) {
           showInputs();
     }
     return null;
  }
  public boolean processInputChange(DynamicBuilderInputDefinition changed)
    {
        if (changed == null)
            return false;
        if(changed.getName().equals("ShowMoreInputs"))
        {
            System.out.println(changed.getBoolean());
            if(changed.getBoolean()) {
              showInputs();
              return true;
            }
            else {
               hideInputs();
               return true;
            }
        }
        return false;
  }
  protected void showInputs() {
     context.findInputDefinition("AdvancedInput1").setVisible(true);
     context.findInputDefinition("AdvancedInput2").setVisible(true);
  }
  protected void hideInputs() {
     context.findInputDefinition("AdvancedInput1").setVisible(false);
     context.findInputDefinition("AdvancedInput2").setVisible(false);
  }
}

If the user disables the checkbox, the coordinator removes the added inputs from the builder call editor. When the builder call editor opens (after the builder call has been added to the model ) the initializeInputs() checks to see if the checkbox is enabled and, if so, displays the two additional inputs.

A simple coordinator that sets input definitions whose <Visible/> value in the builder definition is false to true, altering the builder call editor to display those inputs when the user sets a boolean input to true.

Note: For more information about using a coordinator, see the builder tutorial. Right-click on a IBM® WebSphere Portlet Factory WebApp project and click Factory Feature Set > Add > Tutorials and Samples - Builders.

Parent topic: Overview of builder architecture Related concepts

Implementation of generation behavior

About creating builder definitions

About model-based builder creation

Builder input widgets


Library | Support |