|
||||||||||
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 IValidationDelegate
that can be used as a
managed bean. This class is often subclassed, typically to override
presentation details.
Constructor Summary | |
---|---|
ValidationDelegate()
|
Method Summary | |
---|---|
void |
afterLabelText(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component)
Invoked just before the closing </label> tag is written. |
void |
beforeLabelText(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component)
Invoked just before the actual field label text is written, right after all attributes and informal parameters are done being printed on the <label> tag. |
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. |
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. |
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). |
String |
getFieldInputValue()
Returns the string submitted by the client as the value for the current field. |
List |
getFieldTracking()
Returns all the field trackings as an unmodifiable List. |
protected IFieldTracking |
getFieldTracking(IFormComponent component)
|
IRender |
getFirstError()
A convienience, as most pages just show the first error on the page. |
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. |
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,
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(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(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)
Currently appends a single css class attribute of fieldInvalid if the field
is in error. |
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 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 beforeLabelText(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component)
<label>
tag.
Example, writing content would go here:
<label class="error"> >>here<< LABEL TEXT </label>
beforeLabelText
in interface IValidationDelegate
writer
- The writer to use.cycle
- Current request cycle.component
- Field label is bound to.public void afterLabelText(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component)
</label>
tag is written.
Example, writing content would go here:
<label class="error"> LABEL TEXT >>here<< </label>
afterLabelText
in interface IValidationDelegate
writer
- The writer to use.cycle
- Current request cycle.component
- Field label is bound to.public 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 String getFieldInputValue()
IValidationDelegate
getFieldInputValue
in interface IValidationDelegate
public 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(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, 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(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)
fieldInvalid
if the field
is in error. If the field has a matching constraint of ValidationConstraint.REQUIRED
the fieldMissing
is written instead.
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.
protected IFieldTracking getFieldTracking(IFormComponent component)
public 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 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 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 String getFocusField()
getFocusField
in interface IValidationDelegate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |