Outputing value from backing bean which is an array directly:

Assuming in my backing bean:

 String x []= ....
 public String [] getOutput { return this.x;}

 public String getOutputAsString(){ return Arrays.asString(x);}

then in the output page we get the output :

#{ myBackingbean.outputAsString }

My question is how to eliminate that getOutputAsString() and outputting directly in the ouput page :

I could do just

#{ myBackingbean.output[0])

but for a looping example ?? Imagine something like

for ( i to #{myBackingbean.ouput.length; ){
       #{myBackingbean.ouput [i]; }
    }

How to do that?

Thanks

Upvotes: 1

Views: 155

Answers (1)

BalusC
BalusC

Reputation: 1108732

Just use a tag or component which can iterate over an array. In standard JSF, that are <c:forEach>, <ui:repeat> and <h:dataTable>.

  1. The <c:forEach> runs during view build time and produces JSF components.

    <c:forEach items="#{bean.array}" var="item">
        #{item}
    </c:forEach>
    
  2. The <ui:repeat> runs during view render time and produces no markup.

    <ui:repeat value="#{bean.array}" var="item">
        #{item}
    </ui:repeat>
    
  3. The <h:dataTable> runs during view render time and produces a HTML <table>.

    <h:dataTable value="#{bean.array}" var="item">
        <h:column>#{item}</h:column>
    </h:dataTable>
    

Upvotes: 2

Related Questions