【问题标题】:Dialog element of primefaces not workingprimefaces的对话框元素不起作用
【发布时间】:2013-08-14 20:14:30
【问题描述】:

我正在尝试使用 primefaces 的对话框元素,但它不起作用。所以我尝试了 primefaces 网站中提供的相同代码。但该代码也不起作用。

            <h:panelGrid columns="1" cellpadding="5">
                <p:commandButton id="basic" value="Basic" onclick="PF('dlg1').show();" type="button" />

                <p:commandButton id="modalDialogButton" value="Modal" onclick="PF('dlg2').show();" type="button"/>

                <p:commandButton id="effectsDialogButton" value="Effects" onclick="PF('dlg3').show();" type="button" />
                </h:panelGrid>

                 <p:dialog id="basicDialog" header="Basic Dialog" widgetVar="dlg1" appendToBody="false">
                 <h:outputText value="Resistance to PrimeFaces is futile!" />
                    </p:dialog>

                    <p:dialog id="modalDialog" header="Modal Dialog" widgetVar="dlg2" modal="true" height="100" appendToBody="false">
                        <h:outputText value="This is a Modal Dialog." />
                    </p:dialog>

                    <p:dialog header="Effects" widgetVar="dlg3" showEffect="explode" hideEffect="bounce" height="100" appendToBody="false">
                        <h:outputText value="This dialog has nice effects." />
                    </p:dialog>

这是我页面的标题:

    <!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:p="http://primefaces.org/ui">

【问题讨论】:

  • 提供完整的xhtml代码。

标签: jsf primefaces jsf-1.2


【解决方案1】:

尝试像这样打开您的对话框:

<p:dialog id="modalDialog" header="Modal Dialog" widgetVar="dlg2" modal="true" height="100" appendToBody="false">
           <h:outputText value="This is a Modal Dialog." />
</p:dialog>

<p:commandButton id="modalDialogButton" value="Modal" onclick="dlg2.show();" type="button" process="@this" update="@none"/>

请张贴您的 xhtml 文件的标题并说明您使用的 PrimeFaces 版本。

以下调用:

PF('dlg2').show(); 

不适用于 Primefaces v3.5,它适用于 4.0 及更高版本。 4.0版本支持

dlg2.show();

dlg2.hide();

但不会太久,它会在未来的版本中被弃用,所以请使用PF('dlg2').show();

【讨论】:

  • Yes Kuba....我使用的是 3.5 版....那么我应该使用哪个版本来实现这个功能??
  • PF('dlg2').show();显然适用于 4.0-SNAPSHOT(不知道,尚未测试); dlg2.show() - 适用于我的 v3.5。
  • 您可以使用任何您想要的版本,但要保持一致——据我所知,您使用的是 v3.5,但正在使用 4.0 中的示例(它们可以工作,但不必这样做) .
  • 我找到了解决方案...在 head 部分中,此代码 sn-p 是必需的。
  • 我不确定。 Primefaces 自带 jQuery。
【解决方案2】:

p:commandButton 需要在 h:form 中

【讨论】:

    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 2013-02-19
    • 2014-12-24
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    相关资源
    最近更新 更多