2014-02-15 47 views
0

我想用primeface <p:layout>創建兩個<p:layoutUnit> s。西部<p:layoutUnit>爲菜單和中心<p:layoutUnit>爲點擊菜單上的項目時出現頁面。 因爲<p:menu>必須包裝在<h:form>,所以我的內容在中心,因爲我需要使用表來顯示數據。所以,我的XHTML頁面看起來像以下:如何在PrimeFaces中更新表格layoutUnit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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:ui="http://java.sun.com/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui"> 

    <f:view contentType="text/html"> 
     <h:head> 
      <f:facet name="first"> 
       <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/> 
       <title>PrimeFaces</title> 
      </f:facet> 
     </h:head> 
     <h:body> 
      <p:layout fullPage="true"> 
       <p:layoutUnit position="west" size="175" header="Left" collapsible="true"> 
        <p:menu> 
         <p:submenu label="testUpdate"> 
          <p:menuitem value="open" id="open" actionListener="#{backingBean.open()}" update=":center_form"/> 
          <p:menuitem value="close" id="close" actionListener="#{backingBean.close()}" update=":center_form"/> 
         </p:submenu> 
        </p:menu> 
       </p:layoutUnit> 

       <p:layoutUnit position="center"> 
        <p:panel id="center_panel" rendered="#{backingBean.render}"> 
         <h:form id="center_form"> 
          testing 
         </h:form> 
        </p:panel> 
       </p:layoutUnit> 
      </p:layout> 
     </h:body> 
    </f:view> 
</html> 

和我的web.xml:

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
     <context-param> 
      <param-name>javax.faces.PROJECT_STAGE</param-name> 
      <param-value>Development</param-value> 
     </context-param> 
     <servlet> 
      <servlet-name>Faces Servlet</servlet-name> 
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 
     <servlet-mapping> 
      <servlet-name>Faces Servlet</servlet-name> 
      <url-pattern>/faces/*</url-pattern> 
     </servlet-mapping> 
     <session-config> 
      <session-timeout> 
       30 
      </session-timeout> 
     </session-config> 
     <welcome-file-list> 
      <welcome-file>faces/index.xhtml</welcome-file> 
     </welcome-file-list> 
    </web-app> 

問題是AJAX似乎不能正常工作,當我點擊「打開」和「關閉」,我必須通過手動重新加載頁面來更新我的連接,以便更新頁面。

我可以知道是否可以做? 如果是這樣,我的代碼裏面有什麼不對嗎? 或者我能做些什麼來讓中心layoutUnit在我點擊菜單上的項目時自動更新?

+0

你應該使用'H:head'包括對Ajax的JSF庫。 –

+0

告訴我它是否有效! –

+0

這不是問題,因爲我只是給我的代碼的一部分...否則,頁面無法正常啓動,但不只是一個更新問題..對不起,這.. ..我會粘貼我的完整代碼以後你的網頁 – tanghao

回答

0

添加到您的web.xml:

<listener> 
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
</listener> 

嘗試update="@all"

+0

這不起作用。我添加偵聽器後甚至無法構建。首先我使用Primefaces而不是表面。其次請檢查:(http://forum.primefaces.org/viewtopic.php?f=3&t=6956),@all不受Primefaces支持 – tanghao