如果commandButton中的update ="dlg",则Primefaces p:dialog并不总是显示出来

yan*_*kee 5 primefaces jsf-2

我有一个像这样的jsf facelet页面(非常简化的版本):

    <h:form id="frmAnagPersonName">
        <p:commandButton value="Edit" icon="ui-icon-gear" 
                         update="@form :frmEdit"
                         onsuccess="_dlgEdit.show()"/>
        ...
        <p:dataTable etc...
        ...


    </h:form>

    <p:dialog id="dlgEdit" widgetVar="_dlgEdit" dynamic="true" modal="true" closable="true"
              header="Person Identity">  
        <h:form id="frmEdit" >
            <p:panelGrid id="pnlEdit" columns="2">
                <p:outputLabel id="lblName" for="eName" value="Name"/>
                <p:inputText id="eName" value="#myBean.personName}"
            </p:panelGrid>
        </h:form>
    </p:dialog>  
Run Code Online (Sandbox Code Playgroud)

它工作正常,直到我在对话框中放置一个dynamyc Header:

<p:dialog ... header="#{myBean.header}" ...  >  
Run Code Online (Sandbox Code Playgroud)

我必须在以下位置更改update属性p:commandButton:

update="@form :dlgEdit"  
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,对话框只会在第一次单击按钮时显示.它不会第二次出现,然后再出现......
为什么?如何让对话框始终显示?

谢谢

Bal*_*usC 11

使用oncomplete属性而不是onsuccess属性.

<p:commandButton ... update="@form :dlgEdit" oncomplete="_dlgEdit.show()" />
Run Code Online (Sandbox Code Playgroud)

onsuccess当ajax响应成功到达时,但在基于ajax响应执行ajax更新之前很久就会直接调用该属性.oncomplete成功完成ajax更新后,将调用该属性.另请参阅标记文档<p:commandButton>.

基本上,这是事件调用顺序:

  • onclick 处理程序被调用
  • ajax请求是基于表单数据准备的 process
  • onbegin 处理程序被调用
  • 发送ajax请求
  • 成功检索到ajax响应(HTTP状态代码为200)
  • onsuccess 处理程序被调用
  • 基于的HTML DOM执行ajax更新 update
  • oncomplete 处理程序被调用

  • @partlov:`show()`隐式触发动态加载,但是当在`onsuccess`中使用时,当`update`发生时,内容来自"后退一步",它将被覆盖. (2认同)