[英]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: 例如:
setNodeState
events are fired. 当我按OK按钮后,将触发3个setNodeState
事件。 MultiFileSelectMgmtBean.fileNames
. 这将导致该表具有10个复选框,因为有10个MultiFileSelectMgmtBean.fileNames
。 I select all checkboxes. 我选中所有复选框。 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.