简体   繁体   English

未触发的事件 <h:selectBooleanCheckbox> 在JSF 2中

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

Some problematic bahaviour in my JSF2 project. 我的JSF2项目中存在一些有问题的行为。

I have a dropdown box h:selectOneMenu which trigers a refresh in a page onchange = "submit();" 我有一个下拉框h:selectOneMenu ,它会在onchange = "submit();"页面上触发刷新onchange = "submit();" which in turn causes my h:dataTable to be populated with checkboxes h:selectBooleanCheckbox . 依次导致我的h:dataTable带有复选框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. 问题是我没有从复选框中获取所有 ValueChangeEvent事件-我仅获得与初始下拉选择中的复选框一样多的事件。 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. 创建页面后,我的初始下拉选择产生了3个复选框,即表中的3行。 I select all checkboxes. 我选中所有复选框。
    • After I press OK button, 3 setNodeState events are fired. 当我按OK按钮后,将触发3个setNodeState事件。
  • 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. 创建页面后,我的初始下拉选择产生了3个复选框,即表中的3行。
    • Then I click on a dropdown and select something different. 然后,我单击一个下拉列表并选择其他内容。 This causes the table to have 10 checkoboxes, since there are 10 MultiFileSelectMgmtBean.fileNames . 这将导致该表具有10个复选框,因为有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. 在我按OK之后,奇怪的事情发生了:仅触发了3个setNodeState事件,而不是我期望的10个事件。

Here is xhtml code: 这是xhtml代码:

<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. 问题是支持bean的构造方法。 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. 创建bean时,它首先检查此状态是否已保存,如果是,则加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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