Skip to main content

Posts

Showing posts from March, 2018

Revisiting passing Parameters through EL - this time with functional techniques

The strangest thing about being a developer, to me, is that every time I think I have perfected my technique for something, I revisit it after some time away and find a better way of doing things. So this is my 4th iteration of how to pass and accept parameters through Expression Language. Allow me to introduce... the Mapper. (Quick side note: my old GetMap was based on the Map interface. Mapper is based on DataObject just because it is smaller. Mapper could just as easily implement Map if you prefer. Just as a quick reminder, the goal is to accept a parameter through Expression Language, like so: styleClass="#{MyViewBean.buttonStyle['MyButton']}" public class Mapper implements DataObject, Serializable { public static interface Function { Object map(Object in); } private final Function func; //This will be an anonymous implementation public Mapper(Function func) { this.func = func; } public Object getValue(Object key){ return func.map(key); // Call the an