2
votes

I want to show continuous integer values from a certain min value to max value.

Is there any way of looping from min to max on xhtml page and add loop values to selectItems

Currently I am doing as:

<p:selectOneMenu>
    <f:selectItems value="#{bean.intValuesFrom25ToMaxValue}" var="myInteger" itemValue="#{myInteger}" itemLabel="#{myInteger}" />
</p:selectOneMenu>

NOTE: There is no problem with current solution, but I have a lot of different select one menus whose values are just a continuous range of integers, so for all of the I have to write getter functions? Thats why I want to create a loop on xhtml page.

1
What is the problem with your solution? - flash

1 Answers

5
votes

You can do this with

 <ui:repeat value="#{bean.yourInts}" var="oneInt">
      <f:selectItem value="#{oneInt}" />
 </ui:repeat>

I hope it's correct, I have no chance to try it right now:-)

EDIT

In that case try this

 <c:forEach begin="25" end="100" var="i">
     <f:selectItem value="#{i}" />     
 </c:forEach>

It's not a perfect solution because you are mixing JSTL with JSF (which sometimes causes problem) but in this case is fine because your loop does not use any dynamic values.