Script Component Index ServiceLink

Select
org.apache.tapestry.form.Select
Multiple Select:
 
Description
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
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.

Body: rendered
Informal parameters: allowed
Reserved parameters: "name"

Examples

This examples shows how to setup a standard Select and Option component. Note that Select and Option are typically only used like this when a PropertySelection component is unable to fulfil the required need. Normally, most users will want to use the PropertySelection, since it requires less work, and can express similar semantics with only a single component (instead of three, as will be shown below).

Select a color

<form jwcid="@Form" listener="ognl:listeners.formSubmit">
 Select a color
 <select jwcid="@Select" multiple="ognl:true">
  <span jwcid="@Foreach" source="ognl:visit.colorList" value="ognl:visit.currentColor">
   <option jwcid="@Option" selected="ognl:visit.currentColor.selected" label="ognl:visit.currentColor.label"/>
  </span>
 </select>
</form>	
This example uses a pre-existing collection as the source of the Option list. The Foreach is used to iterate through the list, rendering multiple HTML option elements on the way.
When the form is submitted, Tapestry will take care of setting the selected attribute on any item that has been selected by the user. For this example, that means that a Color object will have it's selected property set to true (see below)

Which produces the following HTML:

<form method="post" name="Form0" action="/componentref">
<input type="hidden" name="service" value="direct/0/SelectPage/$Form"/>
<input type="hidden" name="sp" value="S0"/>
<input type="hidden" name="Form0" value="$Select"/>
Select a color
<select name="$Select" multiple="multiple"> <option value="0">Green</option> <option value="1">Blue</option> <option value="2">Red</option> <option value="3">White</option> <option value="4">Purple</option> <option value="5">Dark Black</option> <option value="6">Fiji Blue</option> </select> </form>
In this example, the page object (the .java file) is not important, since it contains nothing. The example has purposely tied both the option list, and the currently selected value (the Foreach component's value field) to a property of the Visit object.

> The Visit object is defined as follows:


public class Visit implements Serializable {
    private transient List colorList;
    private Color currentColor;
  
    public Collection getColorList() {
        if (colorList == null) {
            colorList = new ArrayList();
            colorList.add(new Color("Green"));
            colorList.add(new Color("Blue"));
            colorList.add(new Color("Red"));
            colorList.add(new Color("White"));
            colorList.add(new Color("Purple"));
            colorList.add(new Color("Dark Black"));
            colorList.add(new Color("Fiji Blue"));
        }
        return colorList;
    }

    public Color getCurrentColor() { return currentColor; }

    public void setCurrentColor(Color value) { 
        currentColor = value;
    }
}

public class Color implements Serializable {
    private String label;
    private boolean selected;

    public Color(String label) {
        setLabel(label);
    }

    public String getLabel() { return label; }

    public void setLabel(String value) {
        label = value;
    }
    
    public boolean getSelected() { return selected; }

    public void setSelected(boolean value) {
        selected = value;
    }
}

Script Component Index ServiceLink