jsf - c:forEach runs always the same amount of loops -


hi i'm trying display tree structure in jsf

for intendation want insert

<span class="intendwidth" /> 

this jsf-code

<ui:repeat value="#{myhandler.entitytree}" var="entitydepthholder">     <p:commandlink action="#{myhandler.toggle(entitydepthholder.entity)}">         <div>             <c:foreach begin="0" end="#{entitydepthholder.depth}">                 <span class="intendwidth" />             </c:foreach>             #{entitydepthholder.depth} #{entitydepthholder.entity.title}         </div>     </p:commandlink> </ui:repeat> 

but reason c:foreach run once, although 1 entitydepthholder.depth 1, others 0

any ideas how insert tag n-times without c:foreach?

the <c:foreach> runs during view build time (that moment when xhtml turned jsf component tree), while <ui:repeat> runs during view render time (that moment when jsf component tree produces html output).

so, when <c:foreach> runs, #{entitydepthholder} available in el scope , evaluates null , in case implicitly coerced 0. begin 0 , end inclusive, end 1 item.

after view build time, jsf component tree ends this:

<ui:repeat value="#{myhandler.entitytree}" var="entitydepthholder">     <p:commandlink action="#{myhandler.toggle(entitydepthholder.entity)}">         <div>             <span class="intendwidth" />             #{entitydepthholder.depth} #{entitydepthholder.entity.title}         </div>     </p:commandlink> </ui:repeat> 

and during view render time, same html repeatedly generated.

you've 2 options fix this:

  1. use <c:foreach> instead of <ui:repeat> on outer loop. caveat is, breaks view scoped beans in mojarra versions older 2.1.18.

  2. use <ui:repeat> instead of <c:foreach> on inner loop. if happen use jsf utility library omnifaces, may find #{of:createarray()} function helpful in this.

    <ui:repeat value="#{of:createarray(entitydepthholder.depth)}"> 

see also:


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -