案例很简单:我想在选择表行并且行选择侦听器决定隐藏它时禁用按钮(在bean中将布尔值设置为false)。以下是我的观点的一部分:
<h:form id="report-configurator">
<p:panel>
<p:outputPanel styleClass="normalText paragraph">
Configure the Templates, the Collections and the Variables (aka Form fields) for the reports.
Define and associate the core elements which are used in the reports.<br/>
[View, edit, add and associate]
</p:outputPanel>
<p:accordionPanel dynamic="true" cache="true" style="width:96%;margin:0 auto;" >
<p:tab title="Templates" titleStyleClass="accordionHeader">
<p:panelGrid columns="2" cellpadding="10" columnClasses="twoEqualColumns top-align, twoEqualColumns top-align">
<p:panel header="Registered Templates">
<p:dataTable id="imagetypes" var="cRImageType"
value="#{reportConfiguratorBean.getCRImageTypes()}"
rowKey="#{cRImageType.imTypeId}"
paginator="true"
paginatorAlwaysVisible="false"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,50"
sortMode="multiple"
rows="10"
filteredValue="#{reportConfiguratorBean.filteredCRImageTypes}"
selection="#{reportConfiguratorBean.selectedCRImageType}"
selectionMode="single" >
<p:ajax event="rowSelect" listener="#{reportConfiguratorBean.setSelectedRow}" update="deleteCommand1" />
<p:ajax event="rowUnselect" listener="#{reportConfiguratorBean.unsetSelectedRow}"/>
...
<f:facet name="footer">
<p:commandButton id="deleteCommand1" onclick="dlg5.show()"
value="Delete"
disabled="#{reportConfiguratorBean.renderedDeleteProtocol}"
update=":report-configurator:deleteSingleImageType" />
以下是我的bean中行选择器的代码:
public void setSelectedRow(SelectEvent event) {
Long imVirtualId = selectedCRImageType.getImTypeId();
virtualId = selectedCRImageType.getImTypeId().toString();
System.out.println(">>>ROW SELECTION LISTENER 2: Selected row for virtualId value: " + virtualId);
this.selectedCRImageType.setImTypeId(imVirtualId);
this.setSelectedCRImageType(selectedCRImageType);
System.out.println(">>> CRImageType object selected: " + selectedCRImageType);
getAssocImTypesOnLoad();
renderedDeleteProtocol = false;
System.out.println(">>>> RENDER DELETE BUTTON: " + renderedDeleteProtocol);
}
行选择侦听器工作,因为我可以按下按钮并删除所选行等等。我还可以看到它将变量'renderedDeleteProtocol'设置为false。问题是按钮声明中'disabled'属性中的按钮没有得到bean响应。
有什么想法吗?
答案 0 :(得分:1)
我认为解决方案是:
<p:commandButton id="associateCommand1" onclick="dlg7.show()"
value="Associate Collections"
update=":report-configurator:associateVariables"
disabled="#{not(reportConfiguratorBean.renderedDeleteProtocol)?'true':'false'}"
action="#{reportConfiguratorBean.setSelectedRow}"/>