Java Reference
In-Depth Information
How about the cases where multiple passthrough attributes need to be set? The JSF 2.2 specification takes care
of these cases by embedding the f:passThroughAttributes inside a JSF component. To set the values for multiple
attributes, store them into a Map<String,Object> that resides within a managed bean, or use EL to define a Map of
key-value pairs.
First, let's take a look at the solution where the value is bound to a Map residing in the managed bean.
<h:outputText id="ptValues" value="Attribute Values" >
<f:passThroughAttributes value="#{ptBean.ptValues}" />
</h:outputText>
Next, we will look at the case where EL is used to specify a Map of name-value pairs to set for the passthrough
attributes.
<h:outputText id="ptValues2" value="Attribute Values" >
<f:passThroughAttributes value="{'first':1,'second':2,'third':3}" />
</h:outputText>
The following code demonstrates the use of each passthrough attribute solution in a JSF view:
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:f=" http://xmlns.jcp.org/jsf/core "
xmlns:h=" http://xmlns.jcp.org/jsf/html "
xmlns:p=" http://xmlns.jcp.org/jsf/passthrough " >
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Passthrough Attribute Examples</title>
</h:head>
<h:body>
<h:form>
Using the passthrough placeholder attribute:
<h:inputText value="#{ptBean.ptValue1}" p:placeholder="Passthrough Value 1">
<f:ajax execute="@this" update="ptValues"/>
</h:inputText>
<br/><br/>
Using the f:passThroughAttribute taghandler:
<h:inputText value="#{ptBean.ptValue2}" >
<f:passThroughAttribute name="ptValue2" value="Passthrough Value 2" />
<f:ajax execute="@this" update="ptValues"/>
</h:inputText>
<br/><br/>
Multiple Passthrough Attributes
<h:outputText id="ptValues" value="Attribute Values" >
<f:passThroughAttributes value="#{ptBean.ptValues}" />
</h:outputText>
</h:form>
</h:body>
</html>
Search WWH ::




Custom Search