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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18660168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 12:48:02  来源:igfitidea点击:

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

javascriptjsfprimefaces

提问by user489041

On the PrimeFaces website, they have many examples of how to use their components. One feature that I find very useful is the ability to show and hide PrimeFaces dialogs. In the examples this is accomplished like this:

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

If you notice in the command button, it calls:

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

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

However, when I try to reproduce this example, my Firebug debugger complains that PFcannot be found. Is there something that I need to add to my JSF page to have access to PF?

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

采纳答案by Manuel D.

You can replace

你可以更换

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

by

经过

oncomplete="dlg.hide();"

回答by Joffrey Hernandez

If you use Primefaces 3.5 or older:

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

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

For Primefaces 4.0 :

对于 Primefaces 4.0 :

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