【问题标题】:Getting Javascript error while using p:commandButton and p:dialog使用 p:commandButton 和 p:dialog 时出现 Javascript 错误
【发布时间】:2026-01-25 06:15:02
【问题描述】:

单击 p:commandButton 以显示 p:dialog 时出现 javacript 错误。

请找出以下错误:

Message: Object doesn't support this property or method
Line: 1
Char: 169
Code: 0
URI: http://localhost:8080/idm/javax.faces.resource/dialog/dialog.js.xhtml?     ln=primefaces&v=2.2.1

Message: Object doesn't support this property or method
 Line: 1
 Char: 133
 Code: 0
 URI: http://localhost:8080/idm/javax.faces.resource/button/button.js.xhtml?ln=primefaces&v=2.2.1

这里是代码块:

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

<p:commandButton value="save"  onclick="dlg1.show();" ></p:commandButton>
     <p:dialog id="basicDialog" header="Basic Dialog" widgetVar="dlg1">  
  <h:outputText value="Resistance to PrimeFaces is futile!" />  
</p:dialog>
      </ui:composition>

所有其他 primefaces 组件都工作正常。

任何帮助将不胜感激。

【问题讨论】:

  • 这是一个旧的和现有的 web 应用程序,还是您刚刚开始使用 PrimeFaces? 2.2.1 是一个非常古老的版本,不建议开始使用过时的库。至于问题,您是否手动包含另一个 jQuery 副本左右?
  • 是的,我们使用的是 PrimeFaces 2.2.1 版本。我们只能使用这个版本来开发我们的应用程序。是的,我们正在使用 jQuery 的另一个副本,但我们想知道我们需要更改哪个文件来显示 primefaces 对话框......你能帮我解决这个问题吗?

标签: javascript jsf primefaces facelets


【解决方案1】:

是的,我们正在使用另一个 jQuery 副本

删除它。 PrimeFaces 作为一个基于 jQuery/jQuery UI 之上的 JSF 组件库,已经自动包含了其捆绑的 jQuery 文件,其中包括对话框组件。 jQuery 的多个副本只会相互冲突,从而导致您所面临的那种 JS 错误。

如果您打算在不一定使用自动包含 PrimeFaces 捆绑的 jQuery 文件的 PrimeFaces 组件的页面上使用 jQuery,则将此行添加到 &lt;h:head&gt;

<h:outputScript library="primefaces" name="jquery/jquery.js" />

这样一来,PrimeFaces 捆绑的 jQuery 文件总是被包含在内,并且如果某些 PrimeFaces 组件碰巧需要它,PrimeFaces 不会自动包含重复的 jQuery 文件。

【讨论】: