67,512
社区成员
发帖
与我相关
我的任务
分享
PropertyDescriptor[] propertyDescriptores = Introspector
.getBeanInfo(clasz).getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptores) {
Method m = propertyDescriptor.getReadMethod();
if (m == null) {
continue;
}
Object ob = m.invoke(object);
request.setAttribute(propertyDescriptor.getName(), ob);
}
如果strtus2 是先去查找Action的Field,而不是去查找 PropertyDescriptor ,就不会出现只有get方法没有属性的方法。问题就出现在这里...
public static final boolean hasGetProperty(OgnlContext context, Object target, Object oname)
throws IntrospectionException, OgnlException
{
Class targetClass = target == null ? null : target.getClass();
String name = oname.toString();
return (hasGetMethod(context, target, targetClass, name)) || (hasField(context, target, targetClass, name));
}
public static final boolean hasSetProperty(OgnlContext context, Object target, Object oname)
throws IntrospectionException, OgnlException
{
Class targetClass = target == null ? null : target.getClass();
String name = oname.toString();
return (hasSetMethod(context, target, targetClass, name)) || (hasField(context, target, targetClass, name));
}
return (hasSetMethod(context, target, targetClass, name)) || (hasField(context, target, targetClass, name));
}
public String getCodeStr() throws Exception {