简体   繁体   中英

Events not fired from <h:selectBooleanCheckbox> in JSF 2

Some problematic bahaviour in my JSF2 project.

I have a dropdown box h:selectOneMenu which trigers a refresh in a page onchange = "submit();" which in turn causes my h:dataTable to be populated with checkboxes h:selectBooleanCheckbox .

The problem is that I don't get all the ValueChangeEvent events from checkboxes - I only get as many events as there were checkboxes in the initial dropdown selection. For example:

  • First case where I don't change value of a dropdown:
    • Page is created and my initial dropdown selection produces 3 checkboxes, ie 3 rows in the table. I select all checkboxes.
    • After I press OK button, 3 setNodeState events are fired.
  • Second case, I do change value of a dropdown:
    • Page is created and my initial dropdown selection produces 3 checkboxes, ie 3 rows in the table.
    • Then I click on a dropdown and select something different. This causes the table to have 10 checkoboxes, since there are 10 MultiFileSelectMgmtBean.fileNames . I select all checkboxes.
    • After I press OK strange thing happens: only 3 setNodeState events are fired, not 10 as I would expect.

Here is xhtml code:

<tr>
<td>
    <h:selectOneMenu 
                             value               = "#{MultiFileSelectMgmtBean.selectedLocationId}" 
                             valueChangeListener = "#{MultiFileSelectMgmtBean.LocationChangeEvent}" 
                             onchange            = "submit();" 
                             styleClass          = "text" style="width: 250px;">
                <f:selectItems 
                             value = "#{MultiFileSelectMgmtBean.locationsListItems}"
                             var   = "location"
                             itemValue = "#{location}"
                             itemLabel = "#{location.label}"> 
                </f:selectItems>
            </h:selectOneMenu>
</td>
</tr>
<tr>
<td>
           <h:dataTable value="#{MultiFileSelectMgmtBean.fileNames}" var="filename">
                    <h:column>
                          <h:selectBooleanCheckbox  value               = "#{MultiFileSelectMgmtBean.fileMap[filename]}"
                                                    valueChangeListener = "#{MultiFileSelectMgmtBean.setNodeState}" 
                                                    title               = "#{filename}"
                                                    />
                          <h:outputText value="#{filename}" styleClass="text"/>
                    </h:column>
        </h:dataTable>          
</td>
</tr>

Problem was the backing bean consturctor. I was always initializing the dropdown box with first selection. Then the event would change it to some other selectin.

Now I am saving the state of dropdown as a session var. When bean is created, it first checks if this state was saved, and if yes load it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM