org.apache.tapestry.corelib.components.TextField

TextField component corresponds to input type="text" element. The value parameter will be editted. TextField is generally used with string values, but other values are acceptible, as long as they can be freely converted back and forth to strings. Includes the size attribute, if a org.apache.tapestry.beaneditor.Width annotation is present on the property bound to the value parameter.

[JavaDoc]

Component Inheritance

Component Parameters

NameTypeFlagsDefaultDefault PrefixDescription
annotationProviderorg.apache.tapestry.ioc.AnnotationProviderpropProvider of annotations used for some defaults. Annotation are usually provided in terms of the value parameter (i.e., from the getter and/or setter bound to the value parameter).
clientIdStringprop:componentResources.idliteralThe id used to generate a page-unique client-side identifier for the component. If a component renders multiple times, a suffix will be appended to the to id to ensure uniqueness. The uniqued value may be accessed via the clientId property.
disabledbooleanfalsepropIf true, then the field will render out with a disabled attribute (to turn off client-side behavior). Further, a disabled field ignores any value in the request when the form is submitted.
labelStringliteralThe user presentable label for the field. If not provided, a reasonable label is generated from the component's id, first by looking for a message key named "id-label" (substituting the component's actual id), then by converting the actual id to a presentable string (for example, "userId" to "User Id").
nullsorg.apache.tapestry.NullFieldStrategydefaultnullfieldstrategyDefines how nulls on the server side, or sent from the client side, are treated. The selected strategy may replace the nulls with some other value. The default strategy leaves nulls alone. Another built-in strategy, zero, replaces nulls with the value 0.
translateorg.apache.tapestry.TranslatorRequiredpropThe object which will perform translation between server-side and client-side representations. If not specified, a value will usually be generated based on the type of the value parameter.
validateorg.apache.tapestry.FieldValidatorvalidateThe object that will perform input validation (which occurs after translation). The translate binding prefix is generally used to provide this object in a declarative fashion.
valueObjectRequiredpropThe value to be read and updated. This is not necessarily a string, a translator may be provided to convert between client side and server side representations. If not bound, a default binding is made to a property of the container matching the component's id. If no such property exists, then you will see a runtime exception due to the unbound value parameter.

Related Components

Examples

Once again, we're basing the example on the order payment screen from the Radio examples. This time we're focusing in on the text field used for entering the credit card number, and we're going to validate that number using a regular expression:

Payment.tml (partial)

            <t:label for="cardNumber"/>:
            <t:textfield t:id="cardNumber"  validate="required,regexp" size="20"/>
The validate parameter is used to specify validations for the field. When it is omitted, the @Validate annotation of the property is used (if present). In any case, this references two of the built-in validations: "required" and "regexp". The "required" validation requires no extra configuration. On the other hand, "regexp" needs to know the regular expression to enforce ... and it should also have a user presentable message.

Payment.properties (partial)

cardnumber-regexp-message=Credit Card numbers consist of 16 digits
cardnumber-regexp=\\d{4}(\\-?\\d{4}){3}
Tapestry uses the page's message catalog as a source of extra validation information. The key is the component id, the name of the validation. The value is given to the validator object ... here it's the regular expression for a credit card number (four sets of four digits, optionally seperated by dashes). The "-message" entry allows the normal error message for the validator to be overridden.

Notes

These same approaches apply consistently to all form control element components.

Back to index