单击第一个复选框时如何检查另一个复选框?我的复选框列表从数据文件中检索 [英] How to check another checkbox when click first checkbox? My checkbox list retrieve from datafile
本文介绍了单击第一个复选框时如何检查另一个复选框?我的复选框列表从数据文件中检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jsf的新手.我的复选框列表从数据表中检索.如果选中了documentId为101的复选框,则系统应自动选择另一个为documentId 102的复选框.如何编写此问题的代码?
I am new in jsf. My checkbox list retrieve from datatable. if checkbox with documentId 101 selected, system should auto select another checkbox which documentId 102. How to code this problem?
<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
.
First of all, you want to show many check boxes, then you should to use selectManyCheckbox
instead of selectBooleanCheckbox
.
让我们创建一个伪示例,如何根据其他示例选择一些值:
Let's create pseudo example, how to choose some value depending other:
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");
}
}
这篇关于单击第一个复选框时如何检查另一个复选框?我的复选框列表从数据文件中检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文