org.apache.tapestry5.corelib.base
abstract public class: AbstractTextField [javadoc |
source]
java.lang.Object
org.apache.tapestry5.corelib.base.AbstractField
org.apache.tapestry5.corelib.base.AbstractTextField
All Implemented Interfaces:
Field
Direct Known Subclasses:
TextArea, TextField, PasswordField
Abstract class for a variety of components that render some variation of a text field. Most of the hooks for user
input validation are in this class.
In particular, all subclasses support the "toclient" and "parseclient" events. These two events allow the normal
Translator (specified by the translate parameter, but often automatically derived by Tapestry) to be
augmented.
If the component container (i.e., the page) provides an event handler method for the "toclient" event, and that
handler returns a non-null string, that will be the string value sent to the client. The context passed to the event
handler method is t he current value of the value parameter.
Likewise, on a form submit, the "parseclient" event handler method will be passed the string provided by the client,
and may provide a non-null value as the parsed value. Returning null allows the normal translator to operate. The
event handler may also throw
org.apache.tapestry5.ValidationException .
Methods from org.apache.tapestry5.corelib.base.AbstractField: |
---|
afterDecorator, beforeDecorator, createDefaultParameterBinding, decorateInsideField, defaultLabel, getClientId, getControlName, getLabel, isDisabled, isRequired, processSubmission, setDecorator, setFormSupport, setup |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.tapestry5.corelib.base.AbstractTextField Detail: |
void begin(MarkupWriter writer) {
String value = tracker.getInput(this);
// If this is a response to a form submission, and the user provided a value.
// then send that exact value back at them.
if (value == null)
{
// Otherwise, get the value from the parameter ...
// Then let the translator and or various triggered events get it into
// a format ready to be sent to the client.
value = fieldValidationSupport.toClient(this.value, resources, translate, nulls);
}
writeFieldTag(writer, value);
translate.render(writer);
validate.render(writer);
resources.renderInformalParameters(writer);
decorateInsideField();
}
|
final AnnotationProvider defaultAnnotationProvider() {
return new AnnotationProvider()
{
public < T extends Annotation > T getAnnotation(Class< T > annotationClass)
{
return resources.getParameterAnnotation("value", annotationClass);
}
};
}
|
final Binding defaultTranslate() {
return defaultProvider.defaultTranslatorBinding("value", resources);
}
|
final Binding defaultValidate() {
return defaultProvider.defaultValidatorBinding("value", resources);
}
|
final Binding defaultValue() {
return createDefaultParameterBinding("value");
} Deprecated! Likely - to be removed in the future, use org.apache.tapestry5.annotations.Parameter#autoconnect()
instead
The default value is a property of the container whose name matches the component's id. May return null if the
container does not have a matching property. |
protected final String getWidth() {
Width width = annotationProvider.getAnnotation(Width.class);
if (width == null) return null;
return Integer.toString(width.value());
}
|
protected boolean ignoreBlankInput() {
return false;
}
|
public boolean isRequired() {
return validate.isRequired();
}
|
protected void processSubmission(String elementName) {
String rawValue = request.getParameter(elementName);
tracker.recordInput(this, rawValue);
try
{
Object translated = fieldValidationSupport.parseClient(rawValue, resources, translate, nulls);
fieldValidationSupport.validate(translated, resources, validate);
// If the value provided is blank and we're ignoring blank input (i.e. PasswordField),
// then don't update the value parameter.
if (!(ignoreBlankInput() && InternalUtils.isBlank(rawValue)))
value = translated;
}
catch (ValidationException ex)
{
tracker.recordError(this, ex.getMessage());
}
}
|
abstract protected void writeFieldTag(MarkupWriter writer,
String value)
|