用commandButton打开PrimeFaces对话框

时间:2017-10-09 11:03:50

标签: jsf primefaces

我在我的应用中定义了这个链接:

<a href="${request.contextPath}/pages/help/applicationHelpVersion.jsf" title="#{msg['menu.version']}" onclick="window.open(this.href, 'applicationHelpVersion','left=20,top=20,width=400,height=300,toolbar=0,resizable=1'); return false;">#{msg['menu.version']}</a>

此解决方案将打开包含当前应用版本号的新浏览器窗口。

我想重新定义它,以便新对话框窗口打开。

我使用的是primefaces,我想使用模态对话框,但在所有示例中都与commandButton结合使用。

这是applicationHelpVersion.xhtml:

<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:f="http://java.sun.com/jsf/core"
        xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:hr="http://java.sun.com/jsf/html"

        template="/layout/helpLayout.xhtml">


    <ui:define name="insert-application-content">
        <div style="text-align:center">
            <h1><h:outputText value="version: "/><span class="applicationVersionContent">${versionContext.productVersion}</span></h1>
            <!--<h1><h:outputText value="stage: "/><span class="applicationVersionContent">${versionContext.productNameExtension}</span></h1>-->
        </div>
    </ui:define>
</ui:composition>

您能帮我解决一下如何使用应用版本打开新的模态对话框吗?我试过这样的事情:

<a href="${request.contextPath}/pages/help/applicationHelpVersion.jsf" title="#{msg['menu.version']}" onclick="PF('dlg1').show();">return false;">#{msg['menu.version']}</a>

<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" height="100">
    <h:outputText value="here will be version of app..."/>
</p:dialog>

我真的不知道在这里设置什么是href参数,或者是否可以这样做。在这种状态下,应用程序版本显示在新的.jsf页面中,但我需要对话框窗口。你能帮我么?谢谢。

1 个答案:

答案 0 :(得分:0)

您不需要在链接上使用href属性,因为您实际上并未链接到其他页面。使用链接的onclick打开对话框,使用Primefaces&#39;像这样的javascript库:

<a onclick="PF('versionDialog').show();">My link text</a>
<p:dialog widgetVar="versionDialog">
    <h:outputText value="#{elToGetVersionInfo}" />
</p:dialog>

通过此示例,您的链接文本将不会像超链接一样设置样式,因为没有href属性。如果您希望将文本设置为链接样式,请在锚标记上使用href="#"

您问题底部的示例已关闭,但您的onclick正在尝试使用widgetVar dlg1代替dlg2,这是对话框的内容。

相关问题