0

I am having problems with the primefaces selectonemenu, it only displays cube.name (the pulldown has the verbiage cube.name not the value of cube.name), here is the code.

    <p:selectOneMenu id="cubeConfigId" value="#{projectModel.selectedProject.cubeConfigId}"  >
  <f:selectItem itemLabel="Select One" itemValue="" />
  <f:selectItems value="#{projectModel.cubeConfigEntities}" var="cube" itemLabel="cube.name" itemValue="cube.cubeConfigId"/>
    </p:selectOneMenu>

what exactly does the var="cube" do?

snafua
  • 75
  • 1
  • 14

1 Answers1

3

You got itemLabel="cube.name" instead of itemLabel="#{cube.name}" (same for itemValue).

What is displayed is determined by itemLabel="cube.name" so you see what you got in label - in this case it's only name (if you do something like this itemLabel="#{cube}" - toString() will be displayed of the Cube entity). What is saved in backing bean is under itemValue.

var="cube" is just iterator for value="#{projectModel.cubeConfigEntities}". If cubeConfigEntities is list of Cube entities then var="cube" is Cube in one loop iteration, in another loop iteration it takes another Cube from list etc. You can access Cube methods by invoking them on cube.

Geinmachi
  • 1,251
  • 1
  • 8
  • 20
  • Thank you it worked and thanks for the var answer. I never thought of it as an iterator but it makes sense now. Thanks – snafua Nov 05 '15 at 22:53