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