2014-02-17 89 views
1

我無法在p:對話框中執行h:form的ajax更新。這是我的xhtml的設計。我沒有嵌套表單。PrimeFaces p:對話框中的ajax更新不起作用

MainPage.xhtml有相應的managedBean - > MainPageBean。

SearchView.xhtml包含managedBean - > searchViewBean。

MainPage.xhtml

​​3210

searchView.xhtml

<h:form prependId='false' id='sv_dataForm'> 
... 
    <p:messages id="sv_messagesId" for="errorMessages" closeable="true" /> 
    <p:inputText value="#{searchViewBean.lastName}" id="lastName" required="true" /> 
    <p:commandButton value="Search" action="#{searchViewBean.search}" update=":sv_dataForm" ajax="true" /> 
    <h:outputText value='#{searchViewBean.numberOfCustomers}' /> 
... 
</h:form> 

當MainPage.xhtml一個按鈕被點擊它顯示一個p:對話框。 p:對話框包含SearchView.xhtml。 SearchView.xhtml包含一個表單。當對姓氏進行簡單搜索時,numberOfCustomers被確定。當我調試代碼時,我可以在searchViewBean的numberOfCustomers中看到值,但是p:dialog沒有更新。但是,如果我有任何驗證錯誤,我可以看到p:消息得到顯示。我不知道爲什麼p:對話框正在更新。如果我做錯了,請告訴我。

謝謝。

回答

0

好吧,我發現這個問題。在searchView.xhtml裏面我正在調用另一個p:對話框(addIndividialDialog),如下面的代碼所示。

searchView.xhtml

<h:form prependId='false' id='sv_dataForm'> 
... 
    <p:messages id="sv_messagesId" for="errorMessages" closeable="true" /> 
    <p:inputText value="#{searchViewBean.lastName}" id="lastName" required="true" /> 
    <p:commandButton value="Search" action="#{searchViewBean.search}" update=":sv_dataForm" ajax="true" /> 
    <p:commandButton id="addButton" value="Add" onclick="addIndividualDialog.show();" /> 
    <h:outputText value='#{searchViewBean.numberOfCustomers}' /> 
... 
</h:form> 

但我已經加入該對話框(addIndividialDialog)盒代碼在MainPage.xhtml如波紋管示出。

MainPage.xhtml

<ui:composition template='/templates/Layout.xhtml'> 
     <ui:define name='content'> 
      <h:form prependId='false' id='dataForm'> 
     ... 
     <h:outputText value="#{mainPageBean.name}" /> 
     <p:commandButton value="Search" onclick="dialogSearchView.show();" /> 
     ... 
     </h:form> 

     <p:dialog id="dialogSearchViewId" widgetVar="dialogSearchView" modal="true" appendToBody="true" dynamic="true"> 
     <ui:include src="searchView.xhtml" /> 
     </p:dialog> 
     <p:dialog header="Add Individual" widgetVar="addIndividualDialog" modal="true" appendToBody="true" dynamic="true"> 
     <ui:include src="addIndividual.xhtml" /> 
     </p:dialog> 
    </ui:define> 
</ui:composition> 

我能夠從searchView.xhtml打開(addIndividialDialog)對話框,當我按一下按鈕,但我不能做searchView.xhtml的更新,我沒有也可以獲取任何錯誤消息。 當我將(addIndividialDialog)對話框代碼移入searchView.xhtml時,所有事情都開始按預期工作。

這爲我工作 -

searchView.xhtml

<h:form prependId='false' id='sv_dataForm'> 
... 
    <p:messages id="sv_messagesId" for="errorMessages" closeable="true" /> 
    <p:inputText value="#{searchViewBean.lastName}" id="lastName" required="true" /> 
    <p:commandButton value="Search" action="#{searchViewBean.search}" update=":sv_dataForm" ajax="true" /> 
    <p:commandButton id="addButton" value="Add" onclick="addIndividualDialog.show();" /> 
    <h:outputText value='#{searchViewBean.numberOfCustomers}' /> 
... 
</h:form> 
<p:dialog header="Add Individual" widgetVar="addIndividualDialog" modal="true" appendToBody="true" dynamic="true"> 
    <ui:include src="addIndividual.xhtml" /> 
</p:dialog> 
1

嵌套表格在HTML無效。當你inclide seachView.xhtml你正在做財產以後這樣的:

<h:form prependId='false' id='dataForm'> 
    ..... 
    <h:form prependId='false' id='sv_dataForm'> 
    ..... 
    </h:form> 
</h:form> 

你必須把號碼:主要^ h之外對話元素:形式。

默認情況下,commandButton的ajax = true,所以你不需要定義它。

+0

嗨Konum我沒有嵌套形式。其實我發現這個問題,但stackoverflow不允許我回答我自己的問題,因爲我沒有足夠的聲譽。 – sreekarN

+0

Ups,我不知道爲什麼我在那裏看到嵌套窗體。很高興你得到它的工作。 –

相關問題