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

问题描述 投票:0回答:1

我是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
}
jsf
1个回答
0
投票

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

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

HTML代码

<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");
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.