jsf - How to define the content of repeater inside composite through its interface? -
i have composite component ui:repeat
, want define content of ui:repeat
through interface of composite.
following code working in myfaces looks more hack since variable name varrepeat
must known outside of composite , works if no other childrens provided should rendered somewhere else.
view
define content of ui:repeat
<comp:myrepeater value="#{of:createintegerarray(1,5)}"> <h:outputtext id="varcomp" value="#{varrepeat}"/> </comp:myrepeater>
composite myrepeater
<composite:attribute name="value" type="java.lang.object"/> <composite:implementation> <ui:repeat var="varrepeat" value="#{cc.attrs.value}"> <composite:insertchildren/> </ui:repeat> </composite:implementation>
that's best can given var
attribute doesn't support el. make clear enduser, document name of 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 exposed in el under 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 showcase application has similar composite long: <os:listdocs>
:
<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>
<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,'/', '.')}" />
as design hint, if use sensible attribute name collection, var
may become more self-documenting. e.g. ask items
value , provide var="item"
.
<my:repeat items="#{[1,2,3,4,5]}"> <h:outputtext value="#{item}"/> </my:repeat>
Comments
Post a Comment