}
// See interface for javadoc
public void evaluate(final ActionBean bean, final ParameterName name, final List<Object> values,
final ValidationMetadata validationInfo, final ValidationErrors errors) {
Expression expr = null;
BeanVariableResolver resolver = null;
if (validationInfo.expression() != null) {
try {
// Make sure we can get an evaluator
ExpressionEvaluator evaluator = getEvaluator();
if (evaluator == null) return;
// If this turns out to be slow we could probably cache the parsed expression
String expression = validationInfo.expression();
expr = evaluator.parseExpression(expression, Boolean.class, null);
resolver = new BeanVariableResolver(bean);
}
catch (ELException ele) {
throw new StripesRuntimeException(
"Could not parse the EL expression being used to validate field " +
name.getName() + ". This is not a transient error. Please double " +
"check the following expression for errors: " +
validationInfo.expression(), ele);
}
}
// Then validate each value we have and add error messages
for (Object value : values) {
// And then if we have an expression to use
if (expr != null) {
try {
resolver.setCurrentValue(value);
Boolean result = (Boolean) expr.evaluate(resolver);
if (!Boolean.TRUE.equals(result)) {
ValidationError error = new ScopedLocalizableError(ERROR_DEFAULT_SCOPE,
ERROR_KEY);
error.setFieldValue(String.valueOf(value));
errors.add(name.getName(), error);