Using f: selectItems var in the passtrough attribute

Can I pass expressions to JSF 2-pass-through attributes? The following code does not work. expression #{country.isoCode} not evaluated.

 <h:selectOneMenu value="#{bean.selectedCountry}" styleClass="selectlist"> <f:selectItems value="#{bean.countries}" var="country" itemLabel="#{country.countryName}" pt:data-icon="flag flag-#{country.isoCode}"/> </h:selectOneMenu> 

I use namespace

 xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" 

and bootstrap-select. To display the image, use the attribute "data-icon". cm:

http://silviomoreto.imtqy.com/bootstrap-select/#data-icon

displayed output:

 <i class="glyphicon flag flag-"></i> 
+5
el jsf-2 managed-bean passthrough-attributes selectonemenu
source share
1 answer

EL is mainly supported / evaluated throughout the Facelet template. Also external tags / attributes. Even in the HTML comments, where many starters then fall. So no problem.

Your specific case, unfortunately, is "by design". Before rendering the first element, <option> <f:selectItems> fully analyzed only once and turns into an iterator, during which all EL expressions will be evaluated. Then the component will iterate over it during the rendering of the <option> elements, during which all transit attributes will be calculated. However, since var already evaluated during the creation of the iterator, it is not available anywhere during the display of forwarding attributes, and ultimately evaluates an empty string.

A fix that will require significant changes to the standard JSF implementation <f:selectItems> . I'm not sure that for the JSF guys, everyone will have ears for you, but you can always try to create a problem .

You can get around this by physically creating multiple instances of <f:selectItem> during the time assembly using <c:forEach> .

 <h:selectOneMenu ...> <c:forEach items="#{bean.countries}" var="country"> <f:selectItem itemValue="#{country}" itemLabel="#{country.countryName}" pt:data-icon="flag flag-#{country.isoCode}" /> </c:forEach> </h:selectOneMenu> 

See also:

  • JSTL in JSF2 Facelets ... makes sense?
+9
source share

All Articles