Suppose I have a handle on an object of type , and I'm told by configuration that it has a bean property of type int
with the name age
. How can I retrieve the getter for this document?
Is there a better way than prepending "get" and capitalizing the "a" in age
, and looking for a method of that name via reflection?
Using * to call all setter methods of java bean The property attribute of <jsp:setProperty> contains '*' as its value. This tag calls only those setter methods of the property whose names are available in the requested form field.
Given this, getters and setters are also known as accessors and mutators, respectively. The getter method returns the value of the attribute. The setter method takes a parameter and assigns it to the attribute. Getters and setters allow control over the values.
Take a look at java.beans.Introspector
. This class allows you to get the list of properties on a class.
If you know property name you can call
Method getter = new PropertyDescriptor(propertyName, beanClass).getReadMethod();
See Also:
java.beans.PropertyDescriptor
java.lang.reflect.Method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With