oncomplete=“PF('dlg').hide();” 导致“找不到 PF”错误

oncomplete="PF('dlg').hide();" causes "PF cannot be found" error

本文关键字:找不到 PF 导致 错误 oncomplete dlg hide      更新时间:2023-09-26

在PrimeFaces网站上,他们有很多如何使用其组件的示例。我发现非常有用的一个功能是能够显示和隐藏PrimeFaces对话框。在示例中,这是按如下方式完成的:

<p:dialog header="Enter FirstName" widgetVar="dlg" resizable="false">  
    <h:form id="form">  
        <h:panelGrid columns="2" style="margin-bottom:10px">  
            <h:outputLabel for="firstname" value="Firstname:" />  
            <p:inputText id="firstname" value="#{pprBean.firstname}" />  
        </h:panelGrid>  
        <p:commandButton id="submitButton" value="Submit" update=":display" oncomplete="PF('dlg').hide();"/>  
    </h:form>  
</p:dialog>  
<p:outputPanel id="display" style="display:block;margin-top:10px;">  
    <h:outputText id="name" value="Hello #{pprBean.firstname}" rendered="#{not empty pprBean.firstname}"/>  
</p:outputPanel>  

如果您在命令按钮中注意到,它会调用:

oncomplete="PF('dlg').hide();"

但是,当我尝试重现此示例时,我的Firebug调试器抱怨找不到PF。我需要向我的 JSF 页面添加一些内容才能访问PF吗?

如果您使用 Primefaces 3.5 或更早版本:

<p:commandButton id="submitButton" value="Submit" update=":display" oncomplete="dlg.hide();"/> 

对于Primefaces 4.0:

<p:commandButton id="submitButton" value="Submit" update=":display" oncomplete="PF('dlg').hide();"/> 

你可以替换

oncomplete="PF('dlg').hide();"

oncomplete="dlg.hide();"