Upload Component Index

ValidField
net.sf.tapestry.valid.ValidField
Age
 
Description
A ValidField is used to get input from the user, and apply some simple validation at the same time. Out of the box, the component can provide validation based on type and length of field input. Of course, it is possible to supply your own IValidator implemenation to make this component do whatever you want.

The ValidField component creates HTML of form: <input type="text" name="personAge" value="25">

Form component that creates a text field that allows for validation of user input and conversion between string and object values. A ValidField uses an Form validationDelegate to track errors at the form level and an validator to to perform validations and convert between Strings and Objects. A validator may be shared my ValidFields in a form.

See Also
Form, TextArea, TextField
Parameters
Name Type Direction Required Default Description
value Object in-out yes   The value to be displayed (on render), and updated (when the form is submitted, if the submitted value is valid). The IValidator converts between object values and Strings.
hidden boolean in no false If true, then the text field is written as a <input type="password"> form element.
type String in no Object The name of a class, to convert input into. Required by some validators to identify the type of conversion from String (typically, validators that convert a numeric amount). If the class is in package java.lang, then the package name can be ommitted. Also, the names of Java scalar types are acceptible.
hidden boolean in no false If true, then the text field is written as a <input type="password"> form element.
disabled boolean in no false Controls whether the text field is active or not. If disabled, then any value that comes up when the form is submitted is ignored. Corresponds to the "disabled" HTML attribute.
displayWidth integer in no   Controls the display width of the text control in the client browser. If unspecified or zero, then the width is left to the client browser to determine. Corresponds to the "size" HTML attribute.
maximumLength integer in no   Controls the maximum characters that the text control will accept. If unspecified or zero, then the value is left to the client browser to determine. Corresponds to the "maxlength" HTML attribute.
displayName String in yes   A textual name for the field that is used when formulating error messages. Also used by the FieldLabel component to properly label the field.
validator IValidator in yes   Object used to convert object values to Strings (for renderring) and to validate and convert Strings into object values (when the form is submitted).

Body: removed
Informal parameters: allowed
Reserved parameters: "name", "type", "value"

Examples

Provides a date validation field.

Enquiry date

<form jwcid="form">
 <table>
  <tr>								
   <td><span jwcid="dateLabel"/></td>
   <td><input jwcid="dateField" displayName="Enquiry Date"/></td>
  </tr>
 </table>
</form>


<bean name="validationDelegate" class="net.sf.tapestry.valid.ValidationDelegate"/>
    
<bean name="dateValidator" class="net.sf.tapestry.valid.DateValidator">
    <set-property name="required">
        <field-value field-name="Boolean.TRUE"/>
    </set-property>
</bean>

<component id="form" type="Form">
    <binding name="listener" expression="listeners.formSubmit"/>
    <binding name="delegate" expression="beans.validationDelegate"/>
</component>
    
<component id="dateLabel" type="FieldLabel">
    <binding name="field" expression="components.dateField"/>
</component>

<component id="dateField" type="ValidField">
    <binding name="value" expression="visit.enquiryDate"/>
    <binding name="validator" expression="beans.dateValidator"/>
</component>


public class EnquiryPage extends BasePage {
    public void formSubmit(IRequestCycle cycle) {
        // Process enquiry date
    }
}

public class Visit implements Serializable {
    private Date enquiryDate = new Date();

    public Date getEnquiryDate() { return enquiryDate; }

    public void setEnquiryDate(Date value) {
        enquiryDate = value;
    }
}

Upload Component Index