如何将 ah:selectBooleanCheckbox 的值映射到 ah:dataTable 中的 ah:dataTable 中?
有问题的 h:selectBooleanCheckbox 位于 ah:dataTable(类别)内的 ah:dataTable(项目)内的 ah:dataTable(附加)中。显示许多项目,每个项目可以有许多附加项。
<h:dataTable value="#{bean.categoryList}" var="category">
<h:column>
<h:dataTable value="#{category.itemList}" var="item">
<h:column>
<h:dataTable value="#{item.extraList}" var="extra">
<h:column>
<!-- The h:selectBooleanCheckbox in question //-->
<h:selectBooleanCheckbox value="#{bean.extraSelectedMap[item.id][extra.id]}"/>
</h:column>
<h:commandLink action="#{bean.add}" value="Add">
</h:dataTable>
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
页面呈现后,我选择一个复选框,然后选择“添加”。在 bean.add 内部
Map<Integer, HashMap<Integer, Boolean>>
有一个空的 HashMap,当我期望它有额外的 id 映射到值 true 时。
上面的代码或整个方法有什么问题?
非常感谢和问候。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您的
h:dataTable
深度为三层。如果要将复选框附加到父托管 bean 属性,则需要考虑所有级别。因此,使用
Map>
作为属性。否则,每个类别的选择都会被覆盖,直到最后一个类别的选定项目最终出现在地图中。其次,您还需要预先创建地图和所有嵌套地图。 JSF 不会为你做这件事。换句话说,
作为替代方案,您还可以考虑仅向
Extra
添加一个Boolean
属性并绑定到它。First, your
h:dataTable
is three levels deep. If you want to attach the checkbox to a parent managed bean property, then you need to take all levels into account. So,with a
Map<Integer, Map<Integer, Map<Integer, Boolean>>>
as property. Otherwise the selections will be overridden for every category until the selected items of the last category ends up in the map.Second, you need to precreate the map and all nested maps as well. JSF won't do that for you. In other words,
As an alternative, you can also consider to just add a
Boolean
property toExtra
and bind to that instead.