Javascript Can';t使用onclick显示primefaces面板

Javascript Can';t使用onclick显示primefaces面板,javascript,jquery,jsf,primefaces,Javascript,Jquery,Jsf,Primefaces,我试图显示一个带有widgetVar和onclick的p:panel,但它只显示了一瞬间。然后它又藏了起来。 当它再次隐藏时,我在浏览器开发控制台中收到以下错误消息: Uncaught TypeError: Cannot read property 'val' of undefined 错误也只在一瞬间出现 这是我的.xhtml页面: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//D

我试图显示一个带有
widgetVar
onclick
的p:panel,但它只显示了一瞬间。然后它又藏了起来。 当它再次隐藏时,我在浏览器开发控制台中收到以下错误消息:

Uncaught TypeError: Cannot read property 'val' of undefined
错误也只在一瞬间出现

这是我的.xhtml页面:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html   xmlns  ="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"  
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui">

    <h:head>
        <h:outputStylesheet library="css" name="style.css" />
        <h:outputScript name="jquery/jquery.js" library="primefaces"/>  
    </h:head>

    <h:body>
        <h:form>
            <p:commandButton value="testbutton" ajax="false" onclick="PF('panelwv').show();" />
            <p:panel widgetVar="panelwv" visible="false" toggleable="true">
                <h:outputText value="Test" />
            </p:panel>
        </h:form>
    </h:body>                   
</html>

我使用的是Primefaces 5.2。

p:commandButton
上使用
ajax=“false”
,而没有指定引用bean的
操作或
actionListener
属性,这会导致此问题。看起来您不需要或不想在服务器上调用任何操作,只需执行一些javascript即可。在这种情况下,将
type=“button”
添加到
p:commandButton

另见

  • 报告第112页

jquery.js将自动包含在内。无需手动添加。当您删除
h:outputScript
时,错误是否消失?不,问题仍然存在。由于“意外”您的webap中有多个版本的PF jar?哦,等等。。。您可以
ajax=false
。。。这是非常不合逻辑的。打开面板,然后完全刷新页面。可能是由于ajax=false而没有任何action/actionListener导致的。我认为您需要将
type='button'
添加到
p:commandButton
中。在这种情况下,没有任何问题。我的webapp中只有primefaces-5.2.jar。