我的jsff上有一个SelectManyChecbox,它绑定到托管bean中的列表。
现在我的问题是,当我点击某个单选按钮时,某些复选框应该被删除,即列表应该更新为具有较少数量的复选框。
现在,当我选择了10个复选框中的5个,现在当我更新列表时,它在复选框中只留下了2个选项...此时ADF面孔引发了一个问题选择应该是有限的和所有。
请告诉我如何在更新列表之前将复选框重置为默认/未选中状态。
还是有其他方法可以摆脱这个错误
答案 0 :(得分:0)
这是我的例子,它有效:
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:document title="main.jsf" id="d1">
<af:form id="f1">
<af:panelGroupLayout id="pgl1">
<af:selectOneRadio label="setValues" id="sor1" autoSubmit="true"
valueChangeListener="#{viewScope.test.onSetValues}" value="#{viewScope.test.values}">
<af:selectItem label="5 values" value="0" id="si2"/>
<af:selectItem label="3 values" value="1" id="si3"/>
</af:selectOneRadio>
<af:selectManyChoice label="selectManyCheckBox" id="smc1" binding="#{viewScope.test.comp}">
<f:selectItems value="#{viewScope.test.list}" id="si1"/>
</af:selectManyChoice>
</af:panelGroupLayout>
</af:form>
</af:document>
public class TestBean {
private ArrayList<SelectItem> list;
private long values;
private RichSelectManyChoice comp;
public TestBean() {
super();
list = new ArrayList<SelectItem>();
restoreList();
}
private void restoreList() {
list.clear();
list.add(new SelectItem(false, "value 1"));
list.add(new SelectItem(false, "value 2"));
list.add(new SelectItem(false, "value 3"));
list.add(new SelectItem(false, "value 4"));
list.add(new SelectItem(false, "value 5"));
}
private void cutList() {
list.clear();
list.add(new SelectItem(false, "value 1"));
list.add(new SelectItem(false, "value 2"));
list.add(new SelectItem(false, "value 3"));
}
public void setList(ArrayList<SelectItem> list) {
this.list = list;
}
public ArrayList<SelectItem> getList() {
return list;
}
public void onSetValues(ValueChangeEvent valueChangeEvent) {
if ((Long)valueChangeEvent.getNewValue() == 0)
restoreList();
else {
cutList();
}
comp.setValue(null);
comp.processUpdates(FacesContext.getCurrentInstance());
AdfFacesContext.getCurrentInstance().addPartialTarget(comp);
}
public void setValues(long values) {
this.values = values;
}
public long getValues() {
return values;
}
public void setComp(RichSelectManyChoice comp) {
this.comp = comp;
}
public RichSelectManyChoice getComp() {
return comp;
}