|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.myfaces.commons.validator.ValidatorBase
org.apache.myfaces.commons.validator.AbstractCompareToValidator
public abstract class AbstractCompareToValidator
Validates this component against another component.
Specify the foreign component with the for={foreign-component-id} attribute.
Valid operator attribute values:
If the comparator attribute is specified, the component values are compared using the specified java.util.Comparator object. If no comparator is specified, the component values must implement Comparable and are compared using compareTo(). If either value or foreign value does not implement Comparable and no Comparator is specified, validation always succeeds.
Put this validator on the bottom-most component to insure that the foreign component's value has been converted and validated first.
However, this validator will attempt to convert and validate the foreign component's value if this has not already occurred. This process may not be identical to the standard JSF conversion and validation process.
The validation error message key is currently hardcoded as
"{0} value <{1}> must be {2} {3} value <{4}>"
whereThe alternateOperatorName attribute can specify a custom operator name. For example, use "after" instead of "greater than" when comparing dates. The message attribute can specify an alternate validation error message key. For example, use "{0} must be {2} {3}" to remove values from the message.
Known issues:
Field Summary | |
---|---|
static java.lang.String |
COMPARE_TO_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the comparison check fails. |
static java.lang.String |
OPERATOR_EQUALS
|
static java.lang.String |
OPERATOR_EQUALS_ALT
|
static java.lang.String |
OPERATOR_EQUALS_ALT2
|
static java.lang.String |
OPERATOR_GREATER_THAN
|
static java.lang.String |
OPERATOR_GREATER_THAN_ALT
|
static java.lang.String |
OPERATOR_GREATER_THAN_OR_EQUALS
|
static java.lang.String |
OPERATOR_GREATER_THAN_OR_EQUALS_ALT
|
static java.lang.String |
OPERATOR_LESS_THAN
|
static java.lang.String |
OPERATOR_LESS_THAN_ALT
|
static java.lang.String |
OPERATOR_LESS_THAN_OR_EQUALS
|
static java.lang.String |
OPERATOR_LESS_THAN_OR_EQUALS_ALT
|
static java.lang.String |
OPERATOR_NOT_EQUALS
|
static java.lang.String |
OPERATOR_NOT_EQUALS_ALT
|
static java.lang.String |
VALIDATOR_ID
The standard converter id for this converter. |
Fields inherited from interface javax.faces.validator.Validator |
---|
NOT_IN_RANGE_MESSAGE_ID |
Constructor Summary | |
---|---|
AbstractCompareToValidator()
|
Method Summary | |
---|---|
protected java.util.Comparator |
createComparator()
|
abstract java.lang.String |
getAlternateOperatorName()
custom operator name in error message (ie "after" instead of "greater than" for dates) |
protected java.lang.String |
getClassCastExceptionMessage(java.lang.String name,
java.lang.Class clazz,
java.lang.Object object)
|
abstract java.lang.Object |
getComparator()
Value binding for an alternate java.util.Comparator object if component values don't implement Comparable |
abstract java.lang.String |
getFor()
The JSF id of the component with which to compare values. |
abstract java.lang.String |
getOperator()
Operator for comparison: equals: eq, ==, =, not equals: ne, !=, greater than: gt, >, less than: lt, <, greater than or equals: ge, >=, less than or equals: le, <= |
protected java.lang.String |
getOperatorForString(java.lang.String operatorSpecified)
|
protected java.lang.String |
nameForOperator(java.lang.String operator)
|
abstract void |
setAlternateOperatorName(java.lang.String alternateOperatorName)
|
abstract void |
setComparator(java.lang.Object comparator)
|
abstract void |
setFor(java.lang.String string)
|
abstract void |
setOperator(java.lang.String operator)
|
void |
validate(javax.faces.context.FacesContext facesContext,
javax.faces.component.UIComponent uiComponent,
java.lang.Object value)
|
protected boolean |
validateOperatorOnComparisonResult(java.lang.String operator,
int result)
|
Methods inherited from class org.apache.myfaces.commons.validator.ValidatorBase |
---|
getDetailMessage, getFacesContext, getFacesMessage, getMessage, getStringValue, getSummaryMessage, getValueExpression, isTransient, restoreAttachedState, restoreState, saveAttachedState, saveState, setDetailMessage, setMessage, setSummaryMessage, setTransient, setValueExpression |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VALIDATOR_ID
The standard converter id for this converter.
public static final java.lang.String COMPARE_TO_MESSAGE_ID
The message identifier of the FacesMessage
to be created if
the comparison check fails.
public static final java.lang.String OPERATOR_EQUALS
public static final java.lang.String OPERATOR_NOT_EQUALS
public static final java.lang.String OPERATOR_GREATER_THAN
public static final java.lang.String OPERATOR_LESS_THAN
public static final java.lang.String OPERATOR_GREATER_THAN_OR_EQUALS
public static final java.lang.String OPERATOR_LESS_THAN_OR_EQUALS
public static final java.lang.String OPERATOR_EQUALS_ALT
public static final java.lang.String OPERATOR_NOT_EQUALS_ALT
public static final java.lang.String OPERATOR_GREATER_THAN_ALT
public static final java.lang.String OPERATOR_LESS_THAN_ALT
public static final java.lang.String OPERATOR_GREATER_THAN_OR_EQUALS_ALT
public static final java.lang.String OPERATOR_LESS_THAN_OR_EQUALS_ALT
public static final java.lang.String OPERATOR_EQUALS_ALT2
Constructor Detail |
---|
public AbstractCompareToValidator()
Method Detail |
---|
protected java.lang.String getOperatorForString(java.lang.String operatorSpecified)
protected java.lang.String nameForOperator(java.lang.String operator)
protected boolean validateOperatorOnComparisonResult(java.lang.String operator, int result)
public void validate(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, java.lang.Object value) throws javax.faces.validator.ValidatorException
javax.faces.validator.ValidatorException
protected java.lang.String getClassCastExceptionMessage(java.lang.String name, java.lang.Class clazz, java.lang.Object object)
protected java.util.Comparator createComparator()
public abstract java.lang.String getFor()
public abstract void setFor(java.lang.String string)
string
- the foreign component_id, on which a value should be validatedpublic abstract java.lang.String getOperator()
public abstract void setOperator(java.lang.String operator)
public abstract java.lang.Object getComparator()
public abstract void setComparator(java.lang.Object comparator)
public abstract java.lang.String getAlternateOperatorName()
public abstract void setAlternateOperatorName(java.lang.String alternateOperatorName)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |