I have a @SessionScoped bean that I would like to use as a map so that I can dynamically get its properties using EL in the view.
myBean['someDynamicProperty']
I have achieved this by implementing java.util.Map, implementing get(Object o) with my application logic and throwing an UnsupportedOperationException in all other overriden Map methods.
@SessionScoped
@Named
public class MyBean implements Map<String, String> {
@Override
public String get(Object key) {
// Application logic here
}
@Override
public boolean containsKey(Object key) {
throw new UnsupportedOperationException();
}
// All other map methods overriden like containsKey
}
The properties are read only and I only need to use the get method from my code, but is it safe not to implement the other Map methods?
Is there a better way to define dynamic properties for EL in a bean?