Custom evaluation of EL expressions - extend ExpressionEvaluator?
I have a model class (corresponding to a database table) with some exclusion flags, where the flags indicated that a field should not be displayed on a page where we choose to apply exclusions. For example, a person may request that their username and date of birth not be listed in a directory search, yet we would still want to show the username/birthdate on a page where the user is looking at their own information. For example:
publicclass Person{
private String name;
private Date birthDate;
private String username;
privateboolean excludeBirthDate;
privateboolean excludeUsername;
// getters and setters
}
I want to write a tag such that I can say in my JSP:
<page:applyExclusions>
...
${person.username} ${person.name} ${person.birthDate}
...
</page:applyExclusions>
and have only the person's name display (if they have requested that the other fields be excluded).
Looking at the tags API, it seems like I would want to have my own ExpressionEvaluator whose evaluate method says something like
public Object evaluate(String expr, Class type, VariableResolver resolver, FunctionMapper mapper){
if (type.equals(Person.class) &&
expr.equals([i]someExcludedField[/i])){
// return empty String or something to say "don't display the actual value"
}
else{
// ok to display value, evaluate like normal
return super.evaluate(expr, type, resolver, mapper);
}
}
Not sure if I'm on the right track with my idea or if there's a better way to accomplish this?

