我是JSF的新手,面临h:selectOneMenu的一个问题。 selectiononeMenu有三个selectionItem值(All,Checked,Unchecked)。每当我更改下拉列表的值时,值更改侦听器将被触发并且视图正在更新。 我必须引入一个按钮,始终将下拉菜单的值设置为All。作为按钮操作的一部分,我创建了一个UISelectOne并将值设置为All。实际上这里的模型正在更新。但下拉选择视图未更新。它仍然显示出旧的价值。
请帮助我解决问题
ActiveTable.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
......
</style>
<!-- Remember to keep the script up to date whenever you change the ids or Hierarchy of components -->
<script type="text/javascript">
....
</script>
<style>
.headerExtended {
height: 70px;
}
</style>
<f:view id="tableview"
locale="#{sessionScope.WW_TRANS_I18N_LOCALE}">
<h:panelGroup id="unsuccessfulAttemptsmsg"
.....
</h:panelGroup>
<f:loadBundle basename="OMAgentResources" var="bundle" />
<div
style="padding: 15px 0px 25px 0px; border: none; margin-bottom: 50px;">
<h:form id="activeForm" prependId="false">
<a4j:region ajaxRendered="true" id="activeRegion">
<a4j:push id="ajaxPush" address="activeTopic" enabled="true"
interval="0">
<a4j:ajax event="dataavailable" render="activeForm" />
</a4j:push>
<a4j:outputPanel id="messagePanel" ajaxRendered="true">
<h:messages />
</a4j:outputPanel>
<br />
<h:panelGrid id="activeTablePanel" columns="1"
styleClass="otContentAreaAlign" width="100%">
<!-- EXTENDED DATA TABLE -->
<rich:extendedDataTable value="#{alctiveBean.rowData}"
var="row" id="activeTable"
rows="#{preferencesBean.batchValue}" selectionMode="none"
style="width: 1177px;" onRowMouseOut="mouseOutRichRow(this)"
onRowDblClick="wuiDataTableSelectRow(this)" sortMode="single"
frozenColumns="2" showColumnControl="true"
onrowmousemove="collapseDropDown()">
<!-- Column for ack/clr selection -->
<rich:column id="ackclrColumn"
style="text-align:center;white-space: nowrap;"
headerClass="headerExtended" width="115px">
<f:facet name="header" id="ackclrHeader">
<h:outputText id="tableformenabledcolumnheadersmall"
value="#{bundle.active_page}" />
<h:panelGroup id="selectionFilterPanel">
<h:selectOneMenu id="selectionFilter"
valueChangeListener="#{activeBean.selectionChangeListener}"
style="text-align:center;">
<f:selectItems value="#{activeBean.selectionList}" />
<a4j:ajax event="change" execute="@this"
render="activeTablePanel,activeTableButtonPanel" />
</h:selectOneMenu>
</h:panelGroup>
</f:facet>
</rich:column>
</rich:extendedDataTable>
</h:panelGrid>
</a4j:region
<h:panelGrid columns="1" id="activeTableButtonPanel"
style="width: 1190px; align:center">
<!-- Command buttons -->
<h:panelGroup>
<a4j:commandButton id="clearFiltersButtonId"
value="#{bundle.activebrowser_page_clr_flt}"
action="#{activeBean.clearFiltersAction}"
disabled="#{!activeBean.isFilterActive}"
render="activeTable,activeTableButtonPanel"
rendered="true"
style="text-align:center"/>
</h:panelGroup>
</h:panelGrid>
</h:form>
</div>
</f:view>
</ui:composition>
</html>
BackEnd Bean:
选择更改侦听器:
public synchronized void selectionChangeListener(ValueChangeEvent event){
if(theSelectionFilter == null) {
setSelectionFilter(new HtmlSelectOneMenu());
} else {
setSelectionFilter(theSelectionFilter);
}
Object oo = event.getNewValue();
if (oo == null) {
return;
}
String allEnum = ((EnumerationFilter) myFilterSelector.getFilter(
FilterSelector.SELECTIONFILTER)).getAllEnumValue();
String s = (String) oo;
EnumerationFilter enumFilter =
(EnumerationFilter)myFilterSelector.getFilter(FilterSelector.SELECTIONFILTER);
String olds[] = enumFilter.getSelectedEnums();
String old = allEnum;
if (olds.length > 0) {
old = olds[0]; //There's never more than one, this is a select-one component
}
enumFilter.setSelections(new String[]{s});
if (enumFilter.allEnumSelected()){
UISelectOne one = (UISelectOne) theSelectionFilter;
one.setValue(allEnum);
}
//Refresh if selection changed
//
if (!old.equals(s)) {
myRefreshRequestHolder.setRefreshRequest(true);
}
}
clearFiltersAction:
public synchronized String clearFiltersAction(){
log.info("activerBean: clearFiltersAction triggered.");
String msg = myResourceBundle.getString("general_page_doneresponse");
myMessageContainer.setMessage(msg);
setFacesMessage(MessageType.MESSAGE_INFO, msg);
log.info("ActiveBean: clearFiltersAction :" + msg);
AlarmFilter filters[] = myFilterSelector.getFilters();
for (int i=0; i < filters.length; ++i){
filters[i].clearFilter();
}
String allEnum = ((EnumerationFilter) myFilterSelector.getFilter(
FilterSelector.SELECTIONFILTER)).getAllEnumValue();
log.info("ActiveBean: clearFiltersAction : clearing SELECTIONFILTER");
UISelectOne one = (UISelectOne) theSelectionFilter;
one.isRendered();
if (one != null) {
one.setValue(allEnum);
log.info("ActiveBean: clearFiltersAction : resetting SELECTIONFILTER to ALL");
}
EnumerationFilter enumFilter =
(EnumerationFilter)myFilterSelector.getFilter(FilterSelector.SELECTIONFILTER);
enumFilter.setSelections(new String[]{allEnum});
refreshIterator(true);
return null;//stay in the same page
}
先谢谢