| <?xml version="1.0" encoding="UTF-8"?> |
| <!-- |
| Copyright 2004, 2005 The Apache Software Foundation |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <document> |
| <properties> |
| <title>Select</title> |
| </properties> |
| <body> |
| |
| <section name="Select"> |
| |
| <p> |
| Implements a component that manages an HTML <code><select></code> 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 |
| <a href="option.html">Option</a> |
| components within a |
| <a href="form.html">Form</a> |
| . |
| </p> |
| <p> |
| Unless multiple selections are required, it is generally easier to use the |
| <a href="propertyselection.html">PropertySelection</a> |
| component. |
| </p> |
| |
| <p> |
| <strong> |
| See also: |
| <a href="../../apidocs/org/apache/tapestry/form/Select.html"> |
| org.apache.tapestry.form.Select |
| </a> |
| , |
| <a href="form.html">Form</a> |
| , |
| <a href="option.html">Option</a> |
| , |
| <a href="radiogroup.html">RadioGroup</a> |
| , |
| <a href="radio.html">Radio</a> |
| , |
| <a href="propertyselection.html">PropertySelection</a> |
| </strong> |
| |
| </p> |
| |
| <section name="Parameters"> |
| <table> |
| <tr> |
| <th>Name</th> |
| <th>Type</th> |
| <th>Required</th> |
| <th>Default</th> |
| <th>Description</th> |
| </tr> |
| <tr> |
| <td>multiple</td> |
| <td>boolean</td> |
| <td>no</td> |
| <td>false</td> |
| <td>If true, the component allows multiple selection.</td> |
| </tr> |
| <tr> |
| |
| <td>disabled</td> |
| <td>boolean</td> |
| <td>no</td> |
| <td>false</td> |
| <td> |
| |
| Controls whether the select is active or not. Corresponds to the |
| "disabled" HTML attribute. |
| </td> |
| </tr> |
| <tr> |
| <td>displayName</td> |
| <td>String</td> |
| <td>no</td> |
| <td></td> |
| <td> |
| The user-presentable name for the component, which will be used by a |
| <a href="fieldlabel.html">FieldLabel</a> |
| connected to the component. |
| </td> |
| </tr> |
| <tr> |
| <td>validators</td> |
| <td> |
| Array or collection of |
| <a |
| href="../../apidocs/org/apache/tapestry/form/validator/Validator.html"> |
| Validator |
| </a> |
| </td> |
| <td>no</td> |
| <td></td> |
| <td> |
| The validators to apply to the component. Something along the lines of: |
| <code>validators:required</code> .<br/><br/> |
| |
| <strong>See also:</strong> <a href="../../usersguide/validation.html">Validation</a> |
| </td> |
| </tr> |
| <tr> |
| <td>id</td> |
| <td>String</td> |
| <td>no</td> |
| <td></td> |
| <td>Sets the id attribute for the rendered <code><select></code> element.</td> |
| </tr> |
| </table> |
| |
| <p> |
| Body: |
| <strong>allowed</strong> |
| </p> |
| |
| <p> |
| Informal parameters: |
| <strong>allowed</strong> |
| </p> |
| |
| <p> |
| Reserved parameters: |
| <em>name</em> |
| </p> |
| |
| </section> |
| |
| <section name="Examples"> |
| <p> |
| In the following example, a user can select several colors (and, because of the |
| validator, he must select at least one). |
| </p> |
| |
| <source xml:space="preserve"><![CDATA[ |
| <form jwcid="@Form" listener="listener:formSubmit"> |
| <label jwcid="@FieldLabel" field="component:colorChooser" displayName="Choose a color">Color</label> |
| <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> |
| ]]></source> |
| |
| <source xml:space="preserve"> |
| 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]); |
| } |
| } |
| |
| } |
| </source> |
| |
| </section> |
| |
| </section> |
| |
| </body> |
| </document> |