myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Parameters In EL" by LanceFrohman
Date Thu, 10 Aug 2006 16:56:51 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by LanceFrohman:
http://wiki.apache.org/myfaces/Parameters_In_EL

New page:
##language:en
== Howto pass parameters in an EL expression ==
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.

=== Example ===
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 DummyMap class ===
{{{
import java.util.Collection;
import java.util.Map;
import java.util.Set;

// 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);
}
}}}

Mime
View raw message