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 Required Default Description
multiple boolean no false If true, the component allows multiple selection.
disabled boolean no false Controls whether the select is active or not. Corresponds to the "disabled" HTML attribute.
displayName String 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 no The validators to apply to the component. Something along the lines of: validators:required .



See also: Validation
translator Translator no The translator to use when displaying and parsing the date.



See also: Validation
id String 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]);
    }
  }

}