I have some classes which extends a superclass, and in the JSP I want to show some attributes of these classes. I only want to make one JSP, but I don\'t know in advance if the
You can readily create a custom function to check for the property, as per vivin's blog post.
In short, if you already have your own taglib its just a matter of creating a static 'hasProperty' method...
import java.beans.PropertyDescriptor;
import org.apache.commons.beanutils.PropertyUtils;
...
public static boolean hasProperty(Object o, String propertyName) {
if (o == null || propertyName == null) {
return false;
}
try
{
return PropertyUtils.getPropertyDescriptor(o, propertyName) != null;
}
catch (Exception e)
{
return false;
}
}
...and adding five lines to your TLD...
hasProperty
my.package.MyUtilClass
boolean hasProperty(java.lang.Object,
java.lang.String)
... and calling it in your JSP