Ste*_*eve 6 el selectonemenu jsf-2 managed-bean passthrough-attributes
我可以将表达式传递给JSF 2 passthrough-attributes吗?以下代码无效.#{country.isoCode}不评估表达式.
<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>
Run Code Online (Sandbox Code Playgroud)
我正在使用命名空间
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
Run Code Online (Sandbox Code Playgroud)
和bootstrap-select.属性"data-icon"用于显示图像.看到:
http://silviomoreto.github.io/bootstrap-select/#data-icon
渲染输出:
<i class="glyphicon flag flag-"></i>
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 11
EL基本上支持/评估Facelet模板中的所有位置.也在标签/属性之外.即使在HTML评论中,许多初学者也会失败.所以这不是问题.
不幸的是,您的具体案例是"按设计".在渲染第一个<option>元素之前,<f:selectItems>is只被解析一次并变成迭代器,在此期间将评估所有EL表达式.然后,组件将在渲染<option>元素的同时迭代它,在此期间将评估所有直通属性.然而,由于var在已创建的迭代过程中评估,它不是可在任何地方呈现直通属性时,最终结果为空字符串.
修复这将需要在标准JSF实现中进行相当多的更改<f:selectItems>.我不确定JSF的人是否会全力以赴,但你总是可以尝试创造一个问题.
您可以通过<f:selectItem>在视图构建期间创建物理上的多个实例来解决此问题<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>
Run Code Online (Sandbox Code Playgroud)