从ManagedBean调用Dialog现在显示PrimeFaces 5

时间:2014-09-30 12:27:20

标签: jsf primefaces dialog

我需要做的是从ManagedBean调用对话框,就像这个展示案例一样: http://www.primefaces.org/showcase/ui/df/basic.xhtml

它看起来非常简单,但我是JSF的新手,也许有一些展示假设我应该知道它可以使它工作。

我所做的与showCase非常相似:

file myDialog.xhtml

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Dialog Test</title>
    <style type="text/css">
.ui-widget {
    font-size: 90%;
}
</style>
</h:head>
<h:body>
    <h1>Dialog Working</h1>
</h:body>
</html>

在“客户”页面中:

<p:commandButton value="Open Dialog" ajax="true"
                actionListener="#{testMB.open}"
                 />

public void open() {
            RequestContext.getCurrentInstance().openDialog("myDialog");
}

当我尝试调用对话框时,没有任何反应!

在Firebug控制台中,我得到了“Widget for var'toidget_frmBody_j_idt88'不可用!”

我注意到showCase中的.xhtml文件没有,所以我尝试了这种方法:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

    <p:dialog widgetVar="testDialog">
        <h1>This is a Dialog</h1>

    </p:dialog>

</html>

RequestContext rc = RequestContext.getCurrentInstance();
rc.execute("PF('testDialog').show()");

我得到了:

TypeError:PF(...)未定义jquery.js:1 “Widget for test'testDialog'不可用!”

我能做些什么来使它有效?

1 个答案:

答案 0 :(得分:0)

这是我的例子。

XHTML

<h:form>
    <h:panelGrid columns="1" cellpadding="1">
        <p:commandButton value="Basic" 
                         process="@this" 
                         update="@form" 
                         actionListener="#{dialogView.openDialog}"/>
    </h:panelGrid>

    <p:dialog header="Basic Dialog" 
              widgetVar="dlg1" 
              minHeight="40">
        <h:outputText value="Dialog open!" />
    </p:dialog>
</h:form>

ManagedBean

public void openDialog() {
    RequestContext rc = RequestContext.getCurrentInstance();
    rc.execute("PF('dlg1').show()");
}