2014-09-30 39 views
0

我需要做的叫我從ManagedBean對話框,正是這樣出現在: http://www.primefaces.org/showcase/ui/df/basic.xhtml呼叫對話框現在顯示PrimeFaces 5

它看起來很瑣碎,但我是新來的JSF,也許有展示櫃假設我應該知道使之發揮作用。

我所做的是非常相似案例:

文件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的widget'widget_frmBody_j_idt88'不可用!」

我注意到從展示.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()"); 

而且我得到了:

類型錯誤:PF(...)是不確定的jquery.js :1 「Widget for var'testDialog'not available!」

我該怎麼做才能使它工作?

回答

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()"); 
} 
+0

應該對話框XHTML頁面分開,也可以是內大XHTML頁面的? – 2015-04-08 09:27:09

+1

@SajjadHTLO你可以使用p:對話框將分隔頁面和嵌套在大型xhtml頁面的內部。不過,我建議您將p:對話框分隔到另一頁,幷包含到您的大型xhtml頁面。 – wittakarn 2015-04-09 01:54:50