【问题标题】:p:commandButton does not perform the operation with a single clickp:commandButton 不执行单击操作
【发布时间】:2013-04-17 04:54:54
【问题描述】:

p:commandButton 不执行单击操作 我有下表

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

我必须单击两次才能运行该操作, 有时是第一次。 在backingbean中有如下方法:

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

    }
}

在调试时,第一次单击进入方法,但好像在列表中找不到要删除的对象。然后单击 sugundo 删除列表对象。

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    在您的 p:commandButton 中使用 action 而不是 actionlistener,因为动作在 f:setPropertyActionListener 之后执行p>

    actionlistener 第一次执行时,它没有找到您的对象集,因为它在 f:setPropertyActionListener 完成之前运行,但这并不总是发生。这就解释了为什么有时单击会起作用。

    【讨论】:

      【解决方案2】:

      我在blog 中做了一个小实验,解释了您的问题。要解决它,您有 2 个选择:

      1. 正如 Hidalgo 上面提到的,从使用 actionListener 切换到 action 属性。
      2. 或者,改变你的actionListener方法如下:

      。按钮:

      <p:commandButton id="selectButton256" title="Eliminar" update="firmasTabla"
                       actionListener="#{clientesMB.deleteSelecPersonaFirmaCliente(car)}" /> 
      

      。豆方法:

      public void deleteSelecPersonaFirmaCliente(Car car) throws Exception {
          // Your logic
      }
      

      【讨论】:

      • 这个答案让我省了很多思考!谢谢!
      猜你喜欢
      • 2022-12-02
      • 2016-03-26
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多