Select

Implements a component that manages an HTML <select> form element. The Select component can take the form of a drop down list (default) or a list selection box if the "multiple" parameter is set to true. The Select component must wrap around Option components within a Form .

Unless multiple selections are required, it is generally easier to use the PropertySelection component.

See also: org.apache.tapestry.form.Select , Form , Option , RadioGroup , Radio , PropertySelection

Parameters

Name Type Direction Required Default Description
multiple boolean in no false If true, the component allows multiple selection.
disabled boolean in no false Controls whether the select is active or not. Corresponds to the "disabled" HTML attribute.
displayName String in no The user-presentable name for the component, which will be used by a FieldLabel connected to the component.
validators Array or collection of Validator , or Validator in no The validators to apply to the component. In many cases, a "validators" binding can help.
id String in no Sets the id attribute for the rendered <select> element.

Body: allowed

Informal parameters: allowed

Reserved parameters: name

Examples

In the following example, a user can select several colors (and, because of the validator, he must select at least one).

<form jwcid="@Form" listener="listener:formSubmit">
 <span jwcid="@FieldLabel" field="component:colorChooser" displayName="Choose a color">Color</span>
 <select jwcid="colorChooser@Select" multiple="ognl:true" validators="validators:required">
  <span jwcid="@Foreach" source="ognl:colors" value="ognl:currentColor" index="ognl:currentColorIndex">
   <option jwcid="@Option" selected="ognl:selection[currentColorIndex]" label="ognl:currentColor"/>
  </span>
 </select>
 <input type="submit"/>
</form>
public abstract class ColorChooser extends BasePage implements PageBeginRenderListener{

  private String[] colors = {"blue", "red", "green", "yellow"};

  public abstract int getCurrentColorIndex();
  public abstract String getCurrentColor();
  public abstract boolean[] getSelection();
  public abstract void setSelection(boolean[] selection);

  public String[] getColors() {
    return colors;
  }

  public void formSubmit() {
    // process form

  }

  public void pageBeginRender(PageEvent event) {
    if (getSelection() == null) {
      setSelection(new boolean[colors.length]);
    }
  }

}