问题
p:commandButton does not perform the operation with a single click I have the following table
<p:dataTable id="firmasTabla" var="car" editable="true" editMode="cell" value="#{clientesMB.itemsPersonaFirmanUtil}" widgetVar="carsTable">
<p:ajax event="cellEdit" listener="#{clientesMB.modiCellPersonaFirma}" update=":form2:growl" />
<p:column headerText="Nro CI" style="width:30%">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.ci}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{car.ci}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Nombre" style="width:60%">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.nombre}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput2" value="#{car.nombre}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:10%">
<p:commandButton id="selectButton256" actionListener="#{clientesMB.deleteSelecPersonaFirmaCliente}"
icon="ui-icon-trash" title="Eliminar" update="firmasTabla">
<f:setPropertyActionListener value="#{car}" target="#{clientesMB.personaFirmasSelect}" />
</p:commandButton>
</p:column>
</p:dataTable>
and I have to click twice to run the operation, sometimes does the first time. in backingbean has the following method:
public void deleteSelecPersonaFirmaCliente() throws Exception {
try {
boolean b = this.getItemsPersonaFirmanUtil().remove(personaFirmasSelect);
boolean b1 = b;
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: deleteSelecPersonaFirmaCliente() " + e.getMessage());
}
}
while debugging happens that the first click enters the method but it is as if the object to delete is not found in the list. Then click the sugundo deleting the list object.
回答1:
use action instead of actionlistener in your p:commandButton since action executes after f:setPropertyActionListener
when actionlistener executes the first time, it didn't find your object set since it runs before that the f:setPropertyActionListener finishes, but this does not happens always. This explains why a single click works sometime.
回答2:
I had a small experiment in my blog that explained your problem. To solve it, you have 2 options:
- As mentioned above by Hidalgo, switch from using
actionListener
toaction
attribute. - Or else, change your
actionListener
method as following:
. Button:
<p:commandButton id="selectButton256" title="Eliminar" update="firmasTabla"
actionListener="#{clientesMB.deleteSelecPersonaFirmaCliente(car)}" />
. Bean method:
public void deleteSelecPersonaFirmaCliente(Car car) throws Exception {
// Your logic
}
来源:https://stackoverflow.com/questions/16043570/pcommandbutton-does-not-perform-the-operation-with-a-single-click