I am sharing this for anyone who may find it useful.
To pass a parameter to a method inside an el expression, extend the DummyMap
class (below) and implement the get(Object obj) method to pass obj as a
parameter
to that method.
As a trivial example, to pass a parameter to the changeToUpperCase() method,
the get() method takes the String, testBean.widget here, as a parameter
and calls changeToUpperCase() with that parameter.
This will result in the page showing "WIDGET".
------------------------------------------------------------------
public class Uppercaser extends DummyMap implements Map {
public String changeToUpperCase(String stg) {
return stg.toUpperCase();
}
public Object get(Object obj) {
return changeToUpperCase((String)obj);
}
}
------------------------------------------------------------------
public class TestBean implements Serializable {
private static final long serialVersionUID = 1L;
private Uppercaser uppercaser = new Uppercaser();
public Uppercaser getUppercaser() {
return uppercaser;
}
public String getWidget() {
return "widget";
}
}
------------------------------------------------------------------
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:view>
<html>
<body>
<h:form>
<h:outputText
value="#{testBean.uppercaser[testBean.widget]}" />
</h:form>
</body>
</html>
</f:view>
------------------------------------------------------------------
the abstract class:
------------------------------------------------------------------
// abstract class used by java server faces to pass parameter to a method as
map key
public abstract class DummyMap implements Map {
public Collection values() {return null;}
public Object put(Object key, Object value) {return null;}
public Set keySet() {return null;}
public boolean isEmpty() {return false;}
public int size() {return 0;}
public void putAll(Map t) {}
public void clear() {}
public boolean containsValue(Object value) {return false;}
public Object remove(Object key) {return null; }
public boolean containsKey(Object key) {return false;}
public Set entrySet() {return null;}
// subclasses should override this method call their method with obj as the
parameter
public abstract Object get(Object obj);
}
------------------------------------------------------------------