public class ValidationDelegate extends java.lang.Object implements IValidationDelegate
IValidationDelegate
that can be used as a managed bean. This
class is often subclassed, typically to override presentation details.Constructor and Description |
---|
ValidationDelegate() |
Modifier and Type | Method and Description |
---|---|
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
List of IFieldTracking s. |
protected FieldTracking |
getComponentTracking()
Returns the
IFieldTracking for 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 property is 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.
|
public ValidationDelegate()
public void clear()
IValidationDelegate
clear
in interface IValidationDelegate
public void clearErrors()
IValidationDelegate
In 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 IValidationDelegate
writer
- the writer to which output should be sentcycle
- the active request cyclecomponent
- the component field that label decoratespublic void writeLabelSuffix(IFormComponent component, IMarkupWriter writer, IRequestCycle cycle)
writeLabelPrefix(IFormComponent,IMarkupWriter,IRequestCycle)
, if the form component
is in error.writeLabelSuffix
in interface IValidationDelegate
protected FieldTracking getComponentTracking()
IFieldTracking
for the current component, if any. The
IFieldTracking
is 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)
IValidationDelegate
name
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 IValidationDelegate
public boolean isInError()
IValidationDelegate
isInError
in interface IValidationDelegate
public java.lang.String getFieldInputValue()
IValidationDelegate
getFieldInputValue
in interface IValidationDelegate
public java.util.List getFieldTracking()
getFieldTracking
in interface IValidationDelegate
public IFieldTracking getCurrentFieldTracking()
IValidationDelegate
IFieldTracking
for the current component, if any. Useful when
displaying error messages for individual fields.getCurrentFieldTracking
in interface IValidationDelegate
public void reset()
IValidationDelegate
reset
in interface IValidationDelegate
public void record(ValidatorException ex)
record(String, ValidationConstraint)
, or
record(IRender, ValidationConstraint)
if the
error renderer property
is 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 IValidationDelegate
message
- message to display (@see RenderString}constraint
- the constraint that was violated, or null if not knownpublic 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 IValidationDelegate
errorRenderer
- object that will render the error message (@see RenderString}constraint
- the constraint that was violated, or null if not knownpublic void record(IFormComponent field, java.lang.String message)
IValidationDelegate
record
in interface IValidationDelegate
field
- 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 IValidationDelegate
protected 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 IValidationDelegate
writer
- 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 void writeAttributes(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component, IValidator validator)
writeAttributes
in interface IValidationDelegate
writer
- 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 void writeSuffix(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component, IValidator validator)
<font color="red">**</font>
.writeSuffix
in interface IValidationDelegate
writer
- 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 IValidationDelegate
public 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 FieldLabel
in a loop (where the
IFormComponent
is renderred more than once) will not provide correct results.public java.util.List getAssociatedTrackings()
List
of IFieldTracking
s. 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
IFieldTracking
is 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()
IValidationDelegate
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). These objects can be rendered or converted to a string (via
toString()).getErrorRenderers
in interface IValidationDelegate
IRender
.public void registerForFocus(IFormComponent field, int priority)
IValidationDelegate
registerForFocus
in interface IValidationDelegate
field
- 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