【问题标题】:Can't show a primefaces panel with onclick无法使用 onclick 显示 primefaces 面板
【发布时间】:2015-08-07 09:44:07
【问题描述】:

我正在尝试显示带有widgetVaronclick 的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。

【问题讨论】:

  • jquery.js 会自动包含在内。无需手动添加。删除 h:outputScript 后错误会消失吗?
  • 不,问题仍然存在。
  • 在您的 webap 中“意外”出现多个版本的 PF jar?
  • 哦等等...你这样做ajax=false...这非常不合逻辑。您打开面板,然后完全刷新页面。也许ajax=false 并且没有任何动作/动作监听器会导致这种情况。我认为在这种情况下您需要将type='button' 添加到p:commandButton
  • 没有一切都很好。我的 web 应用程序中只有 primefaces-5.2.jar。

标签: javascript jquery jsf primefaces


【解决方案1】:

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

另见

【讨论】:

    猜你喜欢
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多