我是jsf的新手。我的复选框列表从数据表中检索。如果选中了documentId 101的复选框,则系统应自动选择另一个documentId 102的复选框。如何编码此问题?
<p:dataTable id="popup1" var="comp1" rows="10"
value="#{ExaBackingBean.managedBean.popupcomp1List}"
editable="true"
selection="#{ExaBackingBean.managedBean.popupcomp1Select}"
rowKey="#{comp1.documentId}" rowIndexVar="index">
<ac:paginator for="popup1"></ac:paginator>
<p:column style="width:3px;text-align:center;" >
<p:selectBooleanCheckbox value="#{comp1.selected}">
<p:ajax listener="#{ExaBackingBean.ckechboxSelectPairingAction(comp1.documentId)}" partialSubmit="true" process="@this" update="@([id$=CompChecklist])" />
</p:selectBooleanCheckbox>
</p:column>
// ExaBackingBean
public void ckechboxSelectPairingAction(int documentId) throws Exception {
if (documentId == 101) {
System.out.println("documentId test"+documentId);
--- checkbox101 & checkbox102 will check
}
答案 0 :(得分:0)
首先,您要显示许多复选框,然后应使用selectManyCheckbox
而不是selectBooleanCheckbox
。
让我们创建一个伪示例,如何根据其他示例选择一些值:
HTML Cloet
<p:selectManyCheckbox id="basic" value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
<p:ajax listener="#{bean.someLogic}" update="someComponent"/>
</p:selectManyCheckbox>
BackedBean
private Map<String, String> availableItems; // +getter (no setter necessary)
private List<String> selectedItems; // +getter +setter
@PostConstruct
public void init() {
availableItems = new LinkedHashMap<String, String>();
availableItems.put("Document1 label", "document1");
availableItems.put("Document2 label", "document2");
availableItems.put("Document3 label", "document3");
}
public void someLogic() {
boolean contains = selectedItems.contains("document1");
if (contains) {
selectedItems.add("document2");
}
}