0

I'm using h selectOneMenu in a datatable and when user press the Set Fixture button i'm saving the value changed in the dropdown, for now i'm using a String variable to get the selected value but the issue is it have the selected value from only the last dropdown. My question is how to get list of all the dropdowns ?

 <h:form id="chooseAlmFixtureForm">
      <p:panel style="width:80%" header="Set Fixture for Alarms">
        <p:dataTable id="tbsetFixtureTable" value="#{setAlmFixtures.alarms}" var="alarmvar" dynamic="false">
             <p:column>
                <p:commandLink value="View" update=":viewUnknownAlarm" immediate="true" oncomplete="viewDialog.show()">
                <f:setPropertyActionListener target="#{currentalarms.viewAlarm}" value="#{alarmvar}"/>
                </p:commandLink>
             </p:column>
             <p:column>
                <f:facet name="header">
                    <h:outputText value="Alarm Time"/>
                </f:facet>
                <h:outputText value="#{alarmvar.recvTime}"/>       
             </p:column>
             <p:column>
                <f:facet name="header">
                    <h:outputText value="Alarm Type"/>
                </f:facet>
                <h:outputText value="#{alarmvar.alarmType}"/>    
             </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Controller Name"/>
                </f:facet>
                <h:outputText value="#{alarmvar.controllerName}"/>    
             </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Controller Type"/>
                </f:facet>
                <h:outputText value="#{alarmvar.controllerType}"/>    
             </p:column>
            <p:column>
            <f:facet name="header">
                    <h:outputText value="Choose Fixture"/>
            </f:facet>
            <h:selectOneMenu id="selectAlarmSite" value="#{setAlmFixtures.selectedFixture}">
                        <f:selectItems value="#{setAlmFixtures.fixtures}" />
            </h:selectOneMenu>
            </p:column>
       </p:dataTable>
       <p:commandButton value="Set Fixtures" actionListener="#{setAlmFixtures.setAlarmsFixtures}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
       </td><td>
       <p:commandButton value="Cancel" actionListener="#{setAlmFixtures.releaseAlarms}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
    </p:panel>
    </h:form>
Nomi Khurram
  • 101
  • 1
  • 11

1 Answers1

0

Currently, your dropdown-value refers to a single variable in your bean (which seems to be selectedFixture of class SetAlmFixtures). How would a single variable represent a state (value) for multiple row (here: alarms)?

You need to link the selected value to the row (alarm) it refers to. To do so, you have several options, two approaches following:

  1. Use the variable of your alarm-object, just the same way as you used them as outputvalues inside the other columns. This way, the alarm's fixture is set directly on value (form) processing. Currently, both of your buttons submit the form (type="submit" is default), depending on what your actionlisteners do, you might consider changing the Cancel-button's type to button.

  2. Map the fixtures and alarms. You could use something like Map<Long, Fixture> fixturemap; mapping alarm-id's to their selected fixture, assuming all alarms have a non-null id. The map's value can be referred by setAlmFixtures.fixturemap['alarmvar.id']. Make sure you provide a getter for the map and the id. Also, you need to initialize the map with the initial fixture values for each alarm.

jp-jee
  • 1,502
  • 3
  • 16
  • 21