我有一个简单的facelet,以表格格式显示产品列表.在每行的最后一列中,有一个用于标记产品以进行删除的复选框.到目前为止,我必须在每一行上放置一个selectBooleanCheckBox,并在Product实体中有一个"mark for deletion"属性,但我认为它很难看,因为我的模型bean中有一些演示文稿.
反正有啊:selectManyCheckBox有哪个f:selectItem分布在dataTable的每一行?
谢谢
Bal*_*usC 13
这t:selectManyCheckbox layout="spread"是一个很好的建议.
作为替代方案,您还可以将h:selectBooleanCheckbox组件绑定到Map<Long, Boolean>属性,该属性Long表示实体ID(或可用于标识行的任何标识符)并Boolean表示已检查的状态.
例如
public class Bean {
private List<Entity> entities;
private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
public void submit() {
for (Entity entity : entities) {
if (checked.get(entity.getId())) {
// Entity is checked. Do your thing here.
}
}
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
同
<h:dataTable value="#{bean.entities}" var="entity">
<h:column>
<h:selectBooleanCheckbox value="#{bean.checked[entity.id]}" />
</h:column>
...
</h:dataTable>
<h:commandButton value="submit" action="#{bean.submit}" />
Run Code Online (Sandbox Code Playgroud)
的Map<Long, Boolean>将被自动地填充所有实体的ID作为地图键和复选框值被设定为与该实体ID作为键相关联的地图的值.