com.opensymphony.xwork2.validator.validators
public class: ExpressionValidator [javadoc |
source]
java.lang.Object
com.opensymphony.xwork2.validator.validators.ValidatorSupport
com.opensymphony.xwork2.validator.validators.ExpressionValidator
All Implemented Interfaces:
ShortCircuitableValidator, Validator
A Non-Field Level validator that validates based on regular expression supplied.
- expression - the Ognl expression to be evaluated against the stack (Must evaluate to a Boolean)
<validators>
<validator type="expression">
<param name="expression"> .... </param>
<message>Failed to meet Ognl Expression .... </message>
</validator>
</validators>
| Methods from com.opensymphony.xwork2.validator.validators.ValidatorSupport: |
|---|
|
addActionError, addFieldError, conditionalParse, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getParse, getValidatorContext, getValidatorType, isShortCircuit, setDefaultMessage, setMessageKey, setParse, setShortCircuit, setValidatorContext, setValidatorType, setValueStack |
| Method from com.opensymphony.xwork2.validator.validators.ExpressionValidator Detail: |
public String getExpression() {
return expression;
}
|
public void setExpression(String expression) {
this.expression = expression;
}
|
public void validate(Object object) throws ValidationException {
Boolean answer = Boolean.FALSE;
Object obj = null;
try {
obj = getFieldValue(expression, object);
} catch (ValidationException e) {
throw e;
} catch (Exception e) {
// let this pass, but it will be logged right below
}
if ((obj != null) && (obj instanceof Boolean)) {
answer = (Boolean) obj;
} else {
log.warn("Got result of " + obj + " when trying to get Boolean.");
}
if (!answer.booleanValue()) {
if (log.isDebugEnabled()) log.debug("Validation failed on expression " + expression + " with validated object "+ object);
addActionError(object);
}
}
|