Methods Summary |
---|
public int | doEndTag()Retrieves one value of a multi-valued property in the specified
bean using a getter method with a String argument. The value is
saved with the specified variable name in the page scope.
Object obj = pageContext.findAttribute(name);
if (obj == null) {
throw new JspException("Variable " + name + " not found");
}
Object propObj = getProperty(obj, property, className);
pageContext.setAttribute(id, propObj);
return SKIP_BODY;
|
private java.lang.Object | getProperty(java.lang.Object bean, java.lang.String property, java.lang.String propClassName)Returns the value of the specified property from the
specified bean.
Object propObj = null;
Class beanClass = bean.getClass();
Class[] params = null;
if (arg != null) {
// If an arg is specified, it must be a String arg
params = new Class[1];
params[0] = String.class;
}
Method method = null;
try {
/*
* Since the method may have an arg, look for it explicitly
* instead of using the standard property lookup method
*/
method = beanClass.getMethod("get" +
property.substring(0, 1).toUpperCase() + property.substring(1),
params);
}
catch (NoSuchMethodException e) {
throw new JspException("A property getter for " + property +
(arg != null ? " with a String argument" : "") +
" not found in " + name);
}
Class propClass = null;
try {
propClass = Class.forName(propClassName);
}
catch (ClassNotFoundException e) {
throw new JspException("Property class " + propClassName + " not found");
}
Class returnType = method.getReturnType();
if (!propClass.isAssignableFrom(returnType)) {
throw new JspException("Property " + property + " is not a " + className);
}
Object[] args = null;
if (arg != null) {
args = new Object[1];
args[0] = arg;
}
try {
propObj = method.invoke(bean, args);
}
catch (Exception e) {
throw new JspException("Failed to get property " + property + " from " + name);
}
return propObj;
|
public void | release()Releases all instance variables.
id = null;
name = null;
property = null;
arg = null;
className = null;
super.release();
|
public void | setArg(java.lang.String arg)Sets the arg attribute, i.e. the String argument value used
by the property getter method to select on of multiple property
values.
this.arg = arg;
|
public void | setClassName(java.lang.String className)Sets the class attribute, i.e. the class name for the property
value.
this.className = className;
|
public void | setId(java.lang.String id)Sets the id attribute, i.e. the name of the variable to hold the
reference to the selected property value.
this.id = id;
|
public void | setName(java.lang.String name)Sets the name attribute, i.e. the name of the variable holding the
reference to the bean with the property to retrieve.
this.name = name;
|
public void | setProperty(java.lang.String property)Sets the property attribute, i.e. the name of the property to
retrieve.
this.property = property;
|