单击第一个复选框时如何选中另一个复选框?我的复选框列表从数据文件中检索



我是jsf的新手。我的复选框列表从数据表中检索。如果选中了文档ID 101的复选框,系统应自动选中另一个复选框,该复选框为文档ID 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
}

首先,您要显示许多复选框,然后您应该使用 selectManyCheckbox 而不是 selectBooleanCheckbox

让我们创建伪示例,如何根据其他值选择一些值:

HTML clode

<p:selectManyCheckbox id="basic" value="#{bean.selectedItems}">
    <f:selectItems value="#{bean.availableItems}" />
    <p:ajax listener="#{bean.someLogic}" update="someComponent"/>
</p:selectManyCheckbox>

背豆

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");
    }
}

最新更新