这是你能得到的最好的var
属性不支持 EL。为了让最终用户清楚,请记录以下名称:var
in <cc:interface shortDescription>
and/or <cc:attribute shortDescription>
.
<cc:interface>
<cc:attribute name="value" type="java.util.Collection"
shortDescription="A collection of items. Each item is exposed in EL under the variable name 'item'." />
<cc:interface>
<cc:implementation>
<ui:repeat value="#{cc.attrs.value}" var="item">
<cc:insertChildren />
</ui:repeat>
</cc:implementation>
Usage:
<my:repeat value="#{bean.list}">
<h:outputText value="#{item}" />
</my:repeat>
The OmniFaces 展示应用程序 http://showcase.omnifaces.orglong 也有类似的组合:<os:listDocs> https://github.com/omnifaces/showcase/blob/master/src/main/webapp/resources/showcase/listdocs.xhtml:
<cc:implementation>
<c:set var="docs" value="#{page.current.documentation[cc.attrs.paths]}" />
<ui:fragment rendered="#{not empty docs}">
<h3>#{cc.attrs.header}</h3>
<ul>
<ui:repeat value="#{docs}" var="path">
<li><a href="#{cc.attrs.url}"><code>#{cc.attrs.label}</code></a></li>
</ui:repeat>
</ul>
</ui:fragment>
</cc:implementation>
Usage https://github.com/omnifaces/showcase/blob/master/src/main/webapp/WEB-INF/templates/showcase.xhtml:
<os:listdocs header="VDL" paths="vdl" url="#{_vdlURL}#{path}.html" label="#{fn:replace(path,'/', ':')}" />
<os:listdocs header="API" paths="api" url="#{_apiURL}#{path}.html" label="#{fn:replace(path,'/', '.')}" />
<os:listdocs header="Source code" paths="api" url="#{_srcURL}#{path}.java" label="#{fn:replace(path,'/', '.')}" />
作为设计提示,如果您为集合使用合理的属性名称,则var
可能会变得更加自我记录。例如。要求items
作为价值并提供var="item"
.
<my:repeat items="#{[1,2,3,4,5]}">
<h:outputText value="#{item}"/>
</my:repeat>