. | |
6. HTML Components6.1 HTMLInputText6.2 HTMLTextArea6.3 HTMLAnchorURL6.4 HTMLSelectThis components is a peer component for the <Select> tag in an HTML form. This component is a specialization of the SelectField. Like the SelectField, this component (using a DefaultSelectModel), can display a selection from a list of objects. It can also change the selection from user input. The selection is made and displayed using the property indicated by the displayPropertyName. The displayPropertyName is effectively the "selection key". If the displayPropertyName is null or blank, then the toString method is used instead. For example, given a list of Address objects, and a displayPropertyName of "zipCode", the display value for "Juneau, AK 99801 USA" would be "99801". To change the selection, you would supply a different zipCode from the list. The HTMLSelect uses a specialized renderer which will create a list of html <Option> tags with the displayPropertyName value for each item in the list. Using the same example as above, after rendering the document would contain: <select name="zip" id="zip"> <option>99801</option> <option>99824</option> <option>99827</option> </select> This component can function in three different ways, depending on the properties you set:
When used for output, the value is rendered in the XML document as a text node by default. If you want the value to be rendered to an attribute of the node instead, you must change the renderer to an AttributeTextFieldRenderer and the the attribute property to the name of the attribute. When used for input, this component receives its value from the InputDispatcher AFTER the openForm method of the ServletForm by default. If you want this component to receive its input earlier (at the same time as Parameters), set the earlyInputNotify property to true. By default, this component uses a DefaultSelectModel. You can change this by overriding the createDefaultModel method or explicitly setting the model property. Setting the ListThe list must be a type of CollectionValueHolder (example: VOCollectionValueHolder or VOListValueHolder). The holder can contain any type of object (but they must all be instances of the same class). If the list is an ObjectArrayValueHolder, then the toString() method is used as the display value (regardless of the displayPropertyName). If used in the bound mode, the whole object itself is stored in the target ValueHolder's object (regardless of the property names listed in the setListPropertyNames method). It is important to make sure that the valueHolder property is the same type as the objects in the ObjectArrayValueHolder or a ModelException will occur. You can also preset the list in the constructor by passing it an array of Objects to be used for the list. The resulting list will be an ObjectArrayValueHolder. The following is an example of this usage: SelectField color = new SelectField(new String[] { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", }); ... private void jbInit() throws Exception { ... color.setParameter("color"); color.setId("color"); ... this.add(color); } This component can be used in a variety of ways. It can be used in an un-bound mode, where the current selection is maintained internally. It can also be used in a bound mode where the current selection is propagated to a value holder. When used in the bound mode, either a single property, or multiple properties can be set in the value holder. The following sections describe the required settings to make for each of the modes. Un-bound Mode (uses internal VariantValueHolder)When used in this mode this component uses an internal VariantValueHolder to hold the current selection. By default a VariantValueHolder is created with a data type of String. To set a different data type use the constructor which takes a data type as a parameter. (example new SelectField(DataTypes.TYPE_INT)). To use this component in the un-bound mode, you must set the following properties:
To use this component in the bound mode, use the same properties as described in the Un-bound Mode, plus the following additional properties:
When a selection is made, the values are copied from the properties in the list to the properties in the valueHolder object. The property names in propertyNames[] and listPropertyNames[] must appear in a corresponding order. A "null" item will always be added to the displayOptionList. When the "null" item is selected, a null will be assigned to the propertyNames[] in the valueHolder object. The actual "null" item to to display is defined by the nullDisplay (default is "--none--"). The format and formatPattern govern the display property in this component. The getText method returns the formatted display property, while the setText method changes the current selection to one whose display matches the given value. If you attempt to setText for an item that is not in the list, a NotInListException will be thrown. 6.5 HTMLCheckboxHTMLCheckBox is a peer component to an HTML input type checkbox. This field is for a stand-alone checkbox and maintains its checked/unchecked state. This component uses an HTMLCheckboxFieldRenderer to render its value. If the CheckboxModel isSelected returns true, then the renderer adds the "checked" attribute to the input tag, otherwise it removed the attribute. The HTML checkbox has a unique behavior in that it only sends a value if it is checked. It does not send anything back if it is un-checked. This behavior requires the use of a defaultValue or uncheckedValue. The unselectedValue is used as the defaultValue for this component. If the unselectedValue is not null it will be used during parameter or input dispatching whenever the checkbox is NOT checked (no parameter is sent). In that case, the unselectedValue will be used as the value for the InputEvent. Limitation: Since input processing will ALWAYS set the value to either the selectedValue (if input present) or unselectedValue (if no input is present), you will want to disable input processing when simply preseting or displaying values. With an HTML checkbox, there is no way to distinguish between an unchecked box or no input submission. To disable input processing, either set the ServletForm's enableInput property to false, or temporarily set the HTMLCheckBox's parameter property to null or blank. This component uses a DefaultCheckboxModel to manage the state. There are only two states for this component: selected or not-selected. To use this component you must first set the the following properties as indicated:
This component can function in three different ways, depending on the properties you set:
When used for input, this component receives its value from the InputDispatcher AFTER the openForm method of the ServletForm by default. If you want this component to receive its input earlier (at the same time as Parameters), set the earlyInputNotify property to true. By default, this component uses a DefaultCheckboxModel. You can change this by overriding the createDefaultModel method or explicitly setting the model property. This component can be used in a variety of ways. It can be used in an un-bound mode, where the current selected state is maintained internally. It can also be used in a bound mode where the current selected state is propagated to a value holder. When used in the bound mode a single property can be set in the value holder. The following sections describe the required settings to make for each of the modes. Un-bound ModeTo use this component in the un-bound mode, you can set the following properties:
To use this component in the bound mode, use the same properties as described in the Un-bound Mode, plus the following additional properties:
|
|
. |