Monday, October 21, 2013

Accessing bean's property dynamically like a map

Assuming we have the following class
@ManagedBean(name="myBean")
public class MyBean {
    private String property1;
    private String property2;

    // getter and setting for property1, property2, ...
}

Normally we are accessing the properties in a bean from xhtml like syntax below.
#{myBean.property1}

But, recently found that we can actually accessing the properties of a bean like accessing a map.
#{myBean['property1']}

#{myBean['property2']}

in normally circumstances, it is nothing special from the traditional way.
But it is relatively useful if we want to dynamically access the properties in a bean.


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...