【问题标题】:p:commandButton p:confirm actionListener not triggeringp:commandButton p:confirm actionListener 未触发
【发布时间】:2015-01-22 01:17:48
【问题描述】:

Primefaces actionListener 在 p:confirmDialog 中不起作用。有人可以帮忙吗? saveRecord 在一个简单的对话框中运行良好。

<p:commandButton value="Save" actionListener="#{EmployeeDetailsComponent.displayInfo}">
    <p:confirm header="Attention" message="test" icon="ui-icon-alert" />
</p:commandButton>

<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" appendToBody="true">
    <p:commandButton value="Save"  action="#{TestComponent.saveRecord(TestComponent.testData)}" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>

【问题讨论】:

标签: jsf-2 primefaces dialog actionlistener confirm


【解决方案1】:

我只是添加一个 div 来使按钮和进程居中,并且该操作完美运行,primefaces 5.1 的示例代码:

 <p:confirmDialog global="true" showEffect="clip"  >
      <div align="center">
         <p:commandButton value="Aceptar" actionListener="#{bienvenidoUI.asignarPSI()}"  update="tablaProceso" icon="ui-icon-check"   process="@this" styleClass="ui-confirmdialog-yes"/>
         <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
      </div>
 </p:confirmDialog>

我只是从一个表中调用confirmDialog:

<p:commandButton   icon="ui-icon-circle-check" title="Asignar PSI"  rendered="#{bienvenidoUI.usr.idUsuario==bienvenidoUI.autorizadorId and min.estado.descripcion=='Proceso'}">
       <f:setPropertyActionListener value="#{min}" target="#{bienvenidoUI.minutaSelected}"  />
       <p:confirm header="Confirmación" message="Esta seguro que desea asignar psi?" icon="ui-icon-alert" />
</p:commandButton>

【讨论】:

    【解决方案2】:

    从确认对话框组件中删除 appendToBody="true" 并在表单中包含保存命令按钮。

    <!DOCTYPE html>
    <f:view xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui">
        <html lang="en">
            <h:head>
            </h:head>
            <h:body id="top">
                <h:form>
                    <p:commandButton value="Save" actionListener="#{simpleBean.displayInfo}" action="#{simpleBean.saveRecord}">
                        <p:confirm header="Attention" message="test" icon="ui-icon-alert" />
                    </p:commandButton>
                </h:form>
    
                <p:confirmDialog closeOnEscape="true" global="true" showEffect="fade" hideEffect="explode">  
                    <p:commandButton value="Save" type="button" styleClass="ui-confirmdialog-yes"/>
                    <p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no"/>
                </p:confirmDialog>
    
            </h:body>
        </html>
    
    </f:view>
    

    SimpleBean.java

    @Named("simpleBean")
    public class SimpleBean implements Serializable{
       public void displayInfo(){
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Display Info works");        
       }
       public String saveRecord(){
          Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Save Record works");        
          return null;
       }
    }
    

    【讨论】:

    • 我在 PF5.1 和 GF4 上对此进行了测试,并且可以正常工作。我已经为您的测试提供了完整的页面和 bean。
    • 是的,上面的代码可以在保存命令中不包含操作的情况下工作。我需要在保存命令中添加操作(请参阅我的代码)。此操作无效
    • 如果您需要添加操作,应将其添加到调用表单的保存命令按钮。参考更新后的代码。
    【解决方案3】:

    你有appendToBody="true",这意味着没有&lt;h:form&gt;来处理点击,因为整个对话框内容直接移动到body下。只需在对话框中添加表单即可。

    <p:confirmDialog global="true" showEffect="fade" hideEffect="explode" appendToBody="true">    
        <h:form>
            <p:commandButton value="Save"  action="#{TestComponent.saveRecord(TestComponent.testData)}" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
            <p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />      
        </h:form>    
    </p:confirmDialog>
    

    【讨论】:

    • @Samantha 您的 bean 的名称是 testComponent 还是 TestComponent?试试小写,或者贴 bean 代码
    • 豆名不错。我有没有对话框的简单保存命令,它可以工作。问题在于对话框中的操作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 2012-01-06
    • 2013-06-24
    相关资源
    最近更新 更多