Class DynaBeanPropertyMapDecorator

  • All Implemented Interfaces:
    java.util.Map<java.lang.String,​java.lang.Object>

    public class DynaBeanPropertyMapDecorator
    extends BaseDynaBeanMapDecorator<java.lang.String>

    Decorates a DynaBean to provide Map behavior.

    The motivation for this implementation is to provide access to DynaBean properties in technologies that are unaware of BeanUtils and DynaBeans - such as the expression languages of JSTL and JSF.

    This can be achieved either by wrapping the DynaBean prior to providing it to the technology to process or by providing a Map accessor method on the DynaBean implementation:

    
             public Map<String, Object> getMap() {
                 return new DynaBeanPropertyMapDecorator(this);
             }

This, for example, could be used in JSTL in the following way to access a DynaBean's fooProperty:

  • ${myDynaBean.map.fooProperty}

Usage

To decorate a DynaBean simply instantiate this class with the target DynaBean:

  • Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean);

The above example creates a read only Map. To create a Map which can be modified, construct a DynaBeanPropertyMapDecorator with the read only attribute set to false:

  • Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean, false);

Limitations

In this implementation the entrySet(), keySet() and values() methods create an unmodifiable Set and it does not support the Map's clear() and remove() operations.

Since:
BeanUtils 1.9.0
Version:
$Id$