0
votes

The case is simple: i want to disable a button when a table row is selected and the row selection listener decides to hide it (sets a boolean value to false in the bean). Here is a portion of my view:

<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" />

and here is the code in my bean for the row selector:

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);
}

The row selection listener works, since i can press the button and delete the selected row and so on. I can also see that it sets the variable 'renderedDeleteProtocol' to false. The problem is that the button in the 'disabled' attribute at button declaration does not get beans response.

Any ideas?

1

1 Answers

1
votes

I think the solution is this:

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