我正在尝试在一个组中有3个复选框(a,b& c),如果选择了b,也会自动选择a。但是当我使用valueChanbgeListener
参数时,它只会在将最新的更改提交到列表之前向我提供selectedItem
列表的信息。此外,此更改也需要反映在前端 - 这意味着我必须在支持bean ui-component
方法的工作完成后更新handleChange()
。
JSF XHTML代码:
<h:form id="form" >
<p:growl id="growl" showDetail="true" sticky="true" />
<h:panelGrid>
<p:selectManyCheckbox value="#{superUser.selectedOptions}"
layout="pageDirection"
onchange="submit()"
valueChangeListener="#{superUser.handleChange}">
<f:selectItems value="#{superUser.allOptions}" />
</p:selectManyCheckbox>
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values"
modal="true"
showEffect="fade"
hideEffect="fade"
widgetVar="dlg">
<p:outputPanel id="display">
<p:dataList value="#{formBean.selected}" var="item">
#{item}
</p:dataList>
</p:outputPanel>
</p:dialog>
</h:form>
支持bean:
@ManagedBean (name="superUser")
@ViewScoped
public class SuperUserBacking implements Serializable {
...
...
private HashMap<Integer, String> monthMap;
private Map<String, String> allOptions;
private List<String> selectedOptions;
public void initializeEventCopyFunction(){
initializeCheckList();
}
private void initializeCheckList(){
allOptions = new HashMap<String, String>();
allOptions.put(this._RACE, this._RACE);
allOptions.put(this._COLUMNS, this._COLUMNS);
allOptions.put(this._MESSAGE, this._MESSAGE);
allOptions.put(this._STAFF, this._STAFF);
allOptions.put(this._EQUIPMENT, this._EQUIPMENT);
selectedOptions = new ArrayList<String>();
}
public void handleChange(){
LOGGER.info("handleChangeMethod Called");
if(selectedOptions==null)
return;
System.out.println("\n");
for(String selected : selectedOptions){
System.out.println("Selected : "+ selected);
}
System.out.println("\n");
}
//GETTERS AND SETTERS
...
}