|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.tapestry.valid.ValidationDelegate
public class ValidationDelegate
A base implementation of IValidationDelegatethat can be used as a managed bean. This
class is often subclassed, typically to override presentation details.
| Constructor Summary | |
|---|---|
ValidationDelegate()
|
|
| Method Summary | |
|---|---|
void |
clear()
Clears all tracking information. |
void |
clearErrors()
Clears all errors, but maintains user input. |
protected FieldTracking |
findCurrentTracking()
Finds or creates the field tracking for the setFormComponent(IFormComponent)
current component. |
java.util.List |
getAssociatedTrackings()
Returns a Listof IFieldTrackings. |
protected FieldTracking |
getComponentTracking()
Returns the IFieldTrackingfor the current component, if any. |
IFieldTracking |
getCurrentFieldTracking()
Returns the IFieldTracking for the current component, if any. |
java.util.List |
getErrorRenderers()
Returns a list of IRender objects, each of which will render an
error message for a field tracked by the delegate, plus any unassociated errors (for which no
specific field is identified). |
java.lang.String |
getFieldInputValue()
Returns the string submitted by the client as the value for the current field. |
java.util.List |
getFieldTracking()
Returns all the field trackings as an unmodifiable List. |
IRender |
getFirstError()
A convienience, as most pages just show the first error on the page. |
java.lang.String |
getFocusField()
Returns the focus field, or null if no form components registered for focus (i.e., they were all disabled). |
boolean |
getHasErrors()
Returns true if any form component has errors. |
java.util.List |
getUnassociatedTrackings()
Like getAssociatedTrackings(), but returns only the unassociated trackings. |
boolean |
isInError()
Returns true if the current field is in error (that is, had bad input submitted by the end user). |
protected boolean |
isInError(IFormComponent component)
Checks to see if the field is in error. |
void |
record(IFormComponent field,
java.lang.String message)
Convienience for recording a standard string messages against a field. |
void |
record(IRender errorRenderer,
ValidationConstraint constraint)
Records error information about the currently selected component, or records unassociated (with any field) errors. |
void |
record(java.lang.String message,
ValidationConstraint constraint)
Invokes record(IRender, ValidationConstraint), after wrapping the message parameter
in a RenderString. |
void |
record(ValidatorException ex)
Invokes record(String, ValidationConstraint), or
record(IRender, ValidationConstraint)if the
error renderer propertyis not null. |
void |
recordFieldInputValue(java.lang.String input)
Records the user's input for the current form component. |
void |
registerForFocus(IFormComponent field,
int priority)
Registers a field for automatic focus. |
void |
reset()
Resets any tracking information for the current field. |
void |
setFormComponent(IFormComponent component)
Invoked before other methods to configure the delegate for the given form component. |
void |
writeAttributes(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
Does nothing. |
void |
writeLabelAttributes(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component)
Does nothing by default. |
void |
writeLabelPrefix(IFormComponent component,
IMarkupWriter writer,
IRequestCycle cycle)
If the form component is in error, places a <font color="red"< around it. |
void |
writeLabelSuffix(IFormComponent component,
IMarkupWriter writer,
IRequestCycle cycle)
Closes the <font> element,started by writeLabelPrefix(IFormComponent,IMarkupWriter,IRequestCycle), if the form component
is in error. |
void |
writePrefix(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
Does nothing. |
void |
writeSuffix(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
Default implementation; if the current field is in error, then a suffix is written. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ValidationDelegate()
| Method Detail |
|---|
public void clear()
IValidationDelegate
clear in interface IValidationDelegatepublic void clearErrors()
IValidationDelegateIn these cases, the user input provided in the request is maintained, but any errors should be cleared out (to prevent unwanted error messages and decorations).
clearErrors in interface IValidationDelegate
public void writeLabelPrefix(IFormComponent component,
IMarkupWriter writer,
IRequestCycle cycle)
writeLabelPrefix in interface IValidationDelegate
public void writeLabelAttributes(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component)
FieldLabel implementation.
writeLabelAttributes in interface IValidationDelegatewriter - the writer to which output should be sentcycle - the active request cyclecomponent - the component field that label decorates
public void writeLabelSuffix(IFormComponent component,
IMarkupWriter writer,
IRequestCycle cycle)
writeLabelPrefix(IFormComponent,IMarkupWriter,IRequestCycle), if the form component
is in error.
writeLabelSuffix in interface IValidationDelegateprotected FieldTracking getComponentTracking()
IFieldTrackingfor the current component, if any. The
IFieldTrackingis usually created in record(String, ValidationConstraint)or
in record(IRender, ValidationConstraint).
Components may be rendered multiple times, with multiple names (provided by the
Form, care must be taken that this method is invoked
after the Form has provided a unique IFormComponent.getName()for the
component.
FieldTracking, or null if the field has no tracking.setFormComponent(IFormComponent)public void setFormComponent(IFormComponent component)
IValidationDelegatename of the form component.
The caller should invoke this with a parameter of null to record unassociated global errors (errors not associated with any particular field).
setFormComponent in interface IValidationDelegatepublic boolean isInError()
IValidationDelegate
isInError in interface IValidationDelegatepublic java.lang.String getFieldInputValue()
IValidationDelegate
getFieldInputValue in interface IValidationDelegatepublic java.util.List getFieldTracking()
getFieldTracking in interface IValidationDelegatepublic IFieldTracking getCurrentFieldTracking()
IValidationDelegateIFieldTracking for the current component, if any. Useful when
displaying error messages for individual fields.
getCurrentFieldTracking in interface IValidationDelegatepublic void reset()
IValidationDelegate
reset in interface IValidationDelegatepublic void record(ValidatorException ex)
record(String, ValidationConstraint), or
record(IRender, ValidationConstraint)if the
error renderer propertyis not null.
record in interface IValidationDelegate
public void record(java.lang.String message,
ValidationConstraint constraint)
record(IRender, ValidationConstraint), after wrapping the message parameter
in a RenderString.
record in interface IValidationDelegatemessage - message to display (@see RenderString}constraint - the constraint that was violated, or null if not known
public void record(IRender errorRenderer,
ValidationConstraint constraint)
Currently, you may have at most one error per field (note the difference between field and component), but any number of unassociated errors.
Subclasses may override the default error message (based on other factors, such as the field and constraint) before invoking this implementation.
record in interface IValidationDelegateerrorRenderer - object that will render the error message (@see RenderString}constraint - the constraint that was violated, or null if not known
public void record(IFormComponent field,
java.lang.String message)
IValidationDelegate
record in interface IValidationDelegatefield - the field to record the error message against, or null to record an unassociated
errormessage - the error message to recordpublic void recordFieldInputValue(java.lang.String input)
IValidationDelegate
recordFieldInputValue in interface IValidationDelegateprotected FieldTracking findCurrentTracking()
setFormComponent(IFormComponent)
current component. If no current component, an unassociated error is created and
returned.
public void writePrefix(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
writePrefix in interface IValidationDelegatewriter - the writer to which output should be sentcycle - the active request cyclecomponent - the component being decoratedvalidator - the validator for the component, or null if the component does have (or doesn't
support) a validator
public void writeAttributes(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
writeAttributes in interface IValidationDelegatewriter - the writer to which output should be sentcycle - the active request cyclecomponent - the component being decoratedvalidator - the validator for the component, or null if the component does have (or doesn't
support) a validator
public void writeSuffix(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
<font color="red">**</font>.
writeSuffix in interface IValidationDelegatewriter - the writer to which output should be sentcycle - the active request cyclecomponent - the component being decoratedvalidator - the validator for the component, or null if the component does have (or doesn't
support) a validatorpublic boolean getHasErrors()
IValidationDelegate
getHasErrors in interface IValidationDelegatepublic IRender getFirstError()
As of release 1.0.9, this returns an instance of IRender, not a String.
protected boolean isInError(IFormComponent component)
FieldLabel. Therefore, using FieldLabelin a loop (where the
IFormComponentis renderred more than once) will not provide correct results.
public java.util.List getAssociatedTrackings()
Listof IFieldTrackings. This is the master list of trackings,
except that it omits and trackings that are not associated with a particular field. May
return an empty list, or null.
Order is not determined, though it is likely the order in which components are laid out on in the template (this is subject to change).
public java.util.List getUnassociatedTrackings()
getAssociatedTrackings(), but returns only the unassociated trackings.
Unassociated trackings are new (in release 1.0.9), and are why interface
IFieldTrackingis not very well named.
The trackings are returned in an unspecified order, which (for the moment, anyway) is the order in which they were added (this could change in the future, or become more concrete).
public java.util.List getErrorRenderers()
IValidationDelegateIRender objects, each of which will render an
error message for a field tracked by the delegate, plus any unassociated errors (for which no
specific field is identified). These objects can be rendered or converted to a string (via
toString()).
getErrorRenderers in interface IValidationDelegateIRender.
public void registerForFocus(IFormComponent field,
int priority)
IValidationDelegate
registerForFocus in interface IValidationDelegatefield - the field requesting focuspriority - a priority level used to determine whether the registered field becomes the focus
field. Constants for this purpose are defined in ValidationConstants.public java.lang.String getFocusField()
getFocusField in interface IValidationDelegate
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||