Deactivating commandButton does not execute a method of the bean located in the action of the button

0

I am working with jsf2 and primefaces. I have a page where there is a table p: dataTable to which I have put checkbox:

            <p:dataTable id="listTable" var="bean"
                     value="#{beanMaquina.lstMaquinas}"
                     selection="#{beanMaquina.lstMaquinasSeleccionadas}"
                     rowKey="#{bean.id}" >

            <p:ajax event="rowSelect" listener="#{beanMaquina.onRowSelect}" update=":form" />
            <p:ajax event="rowUnselect" listener="#{beanMaquina.onRowUnselect}" update=":form" />          
            <p:ajax event="rowSelectCheckbox" listener="#{beanMaquina.onRowSelect}" update=":form" />
            <p:ajax event="rowUnselectCheckbox" listener="#{beanMaquina.onRowUnselect}" update=":form" />

            <p:column selectionMode="multiple" class="check" />

I omit the columns in the table because they have no relevance. On that same page I have some buttons to perform the actions New, modify, delete.

            <span><p:commandButton class="boton" action="/views/empresa/nueva_empresa" immediate="true" title="#{msg.nuevo}" icon="fa fa-fw fa-plus" /></span>
        <span><p:commandButton class="boton" action="#{beanMaquina.modificar()}" disabled="#{beanMaquina.verBtnUnaSel}" title="#{msg.modificar}" icon="fa fa-fw fa-edit"/></span>
        <span><p:commandButton class="boton" action="#{beanMaquina.darBaja()}" disabled="#{beanMaquina.verBtnMultiSel}" title="#{msg.darBaja}" icon="fa fa-fw fa-remove"/></span>

Well, the idea is this. * The button of New (Insert record in BBDD) is always active therefore does not affect at all so I will omit it in the following descriptions. * When loading the page the buttons will remain disabled (disabled). * When we select a checkbox in the table, the modify button is enabled. * When we select more than one checkbox in the table, only the delete button remains active. Logically we can only modify one record while deleting it with one or more records.

This behavior I have done and it works but when I press the modify or delete buttons do not execute their corresponding method in the Bean. However, if I make the buttons are enabled when I load the page if the button methods are executed and the functionality of enabling and disabling buttons with the check also works, but of course, it fails that when loading the page the buttons must be disabled because there is no record selected in the table. This I have tried with disabled and with redered and the result is the same. What solution could apply? I hope I explained it well.

I have not developed it, I only show messages:

public String modificar() {
    verMensajeInformacion(GlobalCons.MSG_MODIFICAR_OK);
    logger.info("Botón Modificar pulsado");
    return null;
}
    
asked by Wall75 01.05.2018 в 15:23
source

2 answers

0

I share a fragment of code that I use and has similar functionality to yours.

New Button (activates other buttons)

 <p:commandButton value="Nueva Factura" 
                  actionListener="#{facturaDataController.numeracionLegajoAlumno()}"
                  icon="ui-icon-plusthick"
                  update=":formFactura"
                  action="#{facturaDataController.activarBotones()}"/>

Activate Buttons Method ()

public void activarBotones() {
    enabled = true;
}

Deactivate Buttons () method

 public void desactivarBotones() {
    enabled = false;
}

Register Button (Default is inactive)

<p:commandButton value="Registrar" icon="ui-icon-check"
                 actionListener="#{facturaDataController.registrar()}"
                 disabled="#{!facturaDataController.enabled}"                                          update=":formFactura,:dlgFormPrestamo:tablaCuota,dlgFormPrestamo:tablaPrestamo"
                 ajax="false"/>

Finally, I can register ()

public void registrar() {

    try {
        // Aqui iria la logica de tu metodo

        // Muestra mensaje de exito
        JSFUtil.addSuccessMessage("Factura registrada exitosamente");
    } catch (Exception e) {
        // muestra mensaje de error
        JSFUtil.addErrorMessage(e.getLocalizedMessage());
    }

    // aqui deberias limpiar los campos del formulario o si quieres desactivar botones
this.desactivarBotones();
}

I hope you serve .. greetings.

    
answered by 01.05.2018 в 17:44
0

I auto respond to myself. Basically the solution was instead of using disabled or rendered, using style

    
answered by 03.05.2018 в 16:52