0

情况很简单:我想在选择表行并且行选择侦听器决定隐藏它时禁用按钮(在 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。问题是按钮声明处的“禁用”属性中的按钮没有得到 bean 响应。

有任何想法吗?

4

1 回答 1

1

我认为解决方案是这样的:

<p:commandButton id="associateCommand1" onclick="dlg7.show()"  
            value="Associate Collections" 
            update=":report-configurator:associateVariables"
            disabled="#{not(reportConfiguratorBean.renderedDeleteProtocol)?'true':'false'}"
            action="#{reportConfiguratorBean.setSelectedRow}"/>
于 2013-10-08T12:23:56.277 回答