PropertyUtils class of Apache commons beanutils library is very useful and provides you ability to modify properties of Java object at runtime. PropertyUtils enables you to write highly configurable code where you can provide name of bean properties and there values from configuration rather than coded in Java program and Apache PropertyUtils can set those properties on Java object at runtime. One popular example of how powerful PropertyUtils can be is display tag which provides rich tabular display for JSP pages, it uses PropertyUtils class to get values of object at runtime and than display it. You can setup properties as column and only selected columns will be displayed. Even larger web framework like Struts and Spring also uses Apache commons beanutils library for getting and setting java properties by name.
PropertyUtils is based on Java reflection but provides convenient method to operate on Java object at runtime. By using PropertyUtils you can get map of all Object properties which enables you to change them at runtime by values coming from all the places like web request, database or configuration files. In this Java tutorial we will example of how to get and set properties of java object using PropertyUtils class at runtime.
This article is in continuation of my earlier post on open source library like How to limit number of user session in web application using Spring Security and How to perform LDAP authentication on windows Active directory using Spring Security. If you haven’t read them already you may find them useful and interesting.