|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry.valid.BaseValidator
public abstract class BaseValidator
Abstract base class for IValidator
. Supports a required and locale property.
Field Summary | |
---|---|
static String |
FIELD_SYMBOL
Input Symbol used to represent the field being validated. |
static String |
FORM_SYMBOL
Input symbol used to represent the IForm containing the field
to the script. |
static String |
FUNCTION_SYMBOL
Output symbol set by the script asthe name of the validator JavaScript function. |
static String |
VALIDATOR_SYMBOL
Input symbol used to represent the validator itself to the script. |
Constructor Summary | |
---|---|
|
BaseValidator()
Standard constructor. |
protected |
BaseValidator(boolean required)
|
Method Summary | |
---|---|
protected String |
buildRequiredMessage(IFormComponent field)
Builds an error message indicating a value for a required field was not supplied. |
protected boolean |
checkRequired(IFormComponent field,
String value)
Invoked to check if the value is null. |
protected String |
formatString(String pattern,
Object arg)
Convienience method for invoking formatString(String, Object[]) . |
protected String |
formatString(String pattern,
Object[] args)
Gets a string from the standard resource bundle. |
protected String |
formatString(String pattern,
Object arg1,
Object arg2)
Convienience method for invoking formatString(String, Object[]) . |
protected String |
getPattern(String override,
String key,
Locale locale)
Gets a pattern, either as the default value, or as a localized key. |
String |
getRequiredMessage()
|
boolean |
isClientScriptingEnabled()
Returns true if client scripting is enabled. |
boolean |
isRequired()
All validators must implement a required property. |
protected void |
processValidatorScript(String scriptPath,
IRequestCycle cycle,
IFormComponent field,
Map symbols)
Invoked (from sub-class implementations of renderValidatorContribution(IFormComponent, IMarkupWriter, IRequestCycle)
to process a standard validation script. |
void |
renderValidatorContribution(IFormComponent field,
IMarkupWriter writer,
IRequestCycle cycle)
This implementation does nothing. |
void |
setClientScriptingEnabled(boolean clientScriptingEnabled)
|
void |
setRequired(boolean required)
|
void |
setRequiredMessage(String string)
Overrides the field-is-required bundle key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.tapestry.valid.IValidator |
---|
toObject, toString |
Field Detail |
---|
public static final String FIELD_SYMBOL
processValidatorScript(String, IRequestCycle, IFormComponent, Map)
,
Constant Field Valuespublic static final String VALIDATOR_SYMBOL
processValidatorScript(String, IRequestCycle, IFormComponent, Map)
,
Constant Field Valuespublic static final String FORM_SYMBOL
IForm
containing the field
to the script.
processValidatorScript(String, IRequestCycle, IFormComponent, Map)
,
Constant Field Valuespublic static final String FUNCTION_SYMBOL
IForm
as a FormEventType.SUBMIT
.
processValidatorScript(String, IRequestCycle, IFormComponent, Map)
,
Constant Field ValuesConstructor Detail |
---|
public BaseValidator()
protected BaseValidator(boolean required)
Method Detail |
---|
public boolean isRequired()
IValidator
isRequired
in interface IValidator
public void setRequired(boolean required)
protected String getPattern(String override, String key, Locale locale)
org.apache.tapestry.valid.ValidationStrings
ResourceBundle
(in the specified locale) is used.
The pattern can then be used with formatString(String, Object[])
.
Why do we not just lump these strings into TapestryStrings.properties? because TapestryStrings.properties is localized to the server's locale, which is fine for the logging, debugging and error messages it contains. For field validation, whose errors are visible to the end user normally, we want to localize to the page's locale.
override
- The override value for the localized string from the bundle.key
- used to lookup pattern from bundle, if override is null.locale
- used to get right localization of bundle.protected String formatString(String pattern, Object[] args)
MessageFormat.format(java.lang.String, java.lang.Object[])
.
pattern
- string the input pattern to be used with
MessageFormat.format(java.lang.String, java.lang.Object[])
.
It may contain replaceable parameters, {0}, {1}, etc.args
- the arguments used to fill replaceable parameters {0}, {1}, etc.protected String formatString(String pattern, Object arg)
formatString(String, Object[])
.
protected String formatString(String pattern, Object arg1, Object arg2)
formatString(String, Object[])
.
protected boolean checkRequired(IFormComponent field, String value) throws ValidatorException
ValidatorException
.
Otherwise, returns true if the value is null.
ValidatorException
protected String buildRequiredMessage(IFormComponent field)
public void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
renderValidatorContribution
in interface IValidator
protected void processValidatorScript(String scriptPath, IRequestCycle cycle, IFormComponent field, Map symbols)
renderValidatorContribution(IFormComponent, IMarkupWriter, IRequestCycle)
to process a standard validation script. This expects that:
IFormComponent
is (ultimately) wrapped by a Body
FUNCTION_SYMBOL
)
scriptPath
- the resource path of the script to executecycle
- The active request cyclefield
- The field to be validatedsymbols
- a set of input symbols needed by the script. These symbols
are augmented with symbols for the field, form and validator. symbols may be
null, but will be modified if not null.
ApplicationRuntimeException
- if there's an error processing the script.public boolean isClientScriptingEnabled()
renderValidatorContribution(IFormComponent, IMarkupWriter, IRequestCycle)
)
before generating client side script.
public void setClientScriptingEnabled(boolean clientScriptingEnabled)
public String getRequiredMessage()
public void setRequiredMessage(String string)
field-is-required
bundle key.
Parameter {0} is the display name of the field.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |