2014-02-17 43 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,我不知道为什么我在那里看到嵌套窗体。很高兴你得到它的工作。 –

相关问题