Jakarta BeanUtils PropertyUtils

I recently had to work with the Jakarta BeanUtils project and found it really useful. I think of it as BeanUseful. The BeanUtils project allows you to easily manipulate a JavaBean object using the static methods from the PropertyUtils class. Here is a simple example of how to update a property value of a JavaBean. Imagine I have a simple Greeting JavaBean class with a single property message.

Of course, object is an instance of a JavaBean with a property named message.

PropertyUtils can also access an indexed method. Here is how you define an indexed property for a JavaBean:

And here is how you would access an index property using PropertyUtils:

In similar fashion, you can access a property that is mapped. Here is an example of how you define a mapped property in a JavaBean:

And here is how you would access a mapped property using PropertyUtils:

The BeanUtils project and Java Reflection in general, is best used in a dynamic setting when you do not know the type of a bean at compile time; that is the strength of Java Reflection, which BeanUtils builds on.

Technorati Tags: , , , ,

Windows Hack »
« Page Redirect
 
Related Posts
Recent Posts
 

No Comment

No comments yet

Leave a reply