无法使用 onclick 显示 primefaces 面板
Can't show a primefaces panel with onclick
我正在尝试用 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 的 action
或 actionListener
属性会导致此问题。看起来您不需要或不想在服务器上调用任何操作,只需执行一些 javascript。在这种情况下,将 type="button"
添加到 p:commandButton
.
另见:
- Primefaces - commandButton does not work
- PF 5.2 docs
的第 112 页
我正在尝试用 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 的 action
或 actionListener
属性会导致此问题。看起来您不需要或不想在服务器上调用任何操作,只需执行一些 javascript。在这种情况下,将 type="button"
添加到 p:commandButton
.
另见:
- Primefaces - commandButton does not work
- PF 5.2 docs 的第 112 页