2012-07-26 19 views
0

我面臨着一個非常類似的問題,我已經在這個問題上做了一張票,但現在問題出現在我的主項目中。前一張票涉及一個測試項目。 Here's到票證的鏈接。我將首先簡要介紹我的項目,然後提供代碼。ui:包含方法打破jsf的ajax功能

這是一個基本的用戶界面,因爲我遺漏了不相關的部分,但是當您啓動webapp時,您應該將其引導至主頁,該主頁通過使用ajax加載了一個介紹。我正在使用名爲Navigation的managedbean,它是一個簡單的pojo,帶有2個註釋和一個名爲'page'的字符串屬性。我已經將該屬性設置爲'intro',所以它默認加載。

// Navigation.java 
@ManagedBean 
@RequestScoped 
public class Navigation { 

    private String page = "intro"; 

    public String getPage() { 
     return page; 
    } 

    public void setPage(String page) { 
    this.page = page; 
    } 
} 

的index.xhtml看起來是這樣的:

<!-- index.xhtml --> 
<h:body> 
    <!-- Navigation --> 
    <h:form> 
     <p:menubar> 
      <p:menuitem value="Home" icon="ui-icon-home" action="#{navigation.setPage('intro')}" update=":contentPanel" /> 
      <p:submenu label="Actions" icon="ui-icon-transferthick-e-w"> 
       <p:submenu label="Employee"> 
        <p:menuitem value="Search" action="#{navigation.setPage('employee/find')}" update=":contentPanel" /> 
       </p:submenu> 
      </p:submenu> 
     </p:menubar> 
    </h:form> 
    <!-- ContentPanel --> 
    <p:panel id="contentPanel" styleClass="content"> 
     <ui:include src="/#{navigation.page}.xhtml" /> 
    </p:panel> 
</h:body> 

現在,當您導航到「操作/員工/新建」文件find.xhtml並得到加載到主網頁,但該表單本身不起作用。這裏的文件:

<!-- find.xhtml --> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:p="http://primefaces.org/ui" 
      xmlns:f="http://java.sun.com/jsf/core"> 
    <f:facet name="header"> 
     Create new employee 
    </f:facet> 
    <h:outputLabel value="User ID: " for="userId" /> 
    <p:inputText value="#{managedEmployee.userId}" id="userId" /> 
    <p:commandButton value="Show" update="result" /> 
    <h:outputText id="result" value="#{managedEmployee.userId}" /> 
</ui:composition> 

那麼用戶將能夠在輸入表單用戶ID和按下命令按鈕時,將顯示形式附近。很明顯,我必須做錯事,但我似乎無法弄清楚。我不喜歡說,但我渴望得到答案。

在此先感謝!

回答

0

我發現我的問題的解決方案。不知道是什麼原因,但是如果我圍繞ui中的代碼:使用h:form組合並添加該表單id以在其工作的鏈接上更新。 希望這可以幫助別人遇到它時。乾杯

<p:menuitem value="Create" action="#{navigationBean.setPage('employee/create')}" update=":contentPanel :form" /> 
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.org/ui"> 
    <h:form id="form"> 
    ... 
    </h:form> 
</ui:composition> 
0

我可能沒有理解這個問題,但是你沒有在你的commandButton上設置動作,所以當然它不會做任何事情。

<p:commandButton value="Show" update="result" /> 

應該有類似

<p:commandButton value="Show" update="result" action="#{backer.method}"/> 
+0

我不認爲這是它,因爲當我手動包括像這樣的文件:<用戶界面:包括SRC =「/員工/ find.xhtml」 />,形式的作品。但是,當我使用#{navigation.page}並導航到表單時,表單確實會加載到主頁面上,但會停止工作。 – mokuril 2012-07-27 06:47:43

+0

哦,我想我明白你現在問什麼。你可以驗證生成的html標記在兩種方式中都是相同的嗎?您是否也在控制檯中出現錯誤? – Catfish 2012-07-27 13:49:41

+0

我沒有看到任何錯誤,並且來源似乎匹配。我一直在研究這個問題,這可能與客戶端和服務器端有關。 – mokuril 2012-07-30 07:16:54