Primefaces动态overlayPanel只显示一次

问题描述 投票:7回答:3

我有一个带有按钮的表单,可打开Primafaces overlayPanel。在面板中有另一个按钮执行Ajax操作,然后关闭叠加层。 这是一个完全没有Ajax操作的简化版本:

<h:form>
    <p:commandButton id="button1" value="Open overlay" type="button"/>
    <p:overlayPanel for="button1" widgetVar="ovl" dynamic="true">
        <p:commandButton value="Close" oncomplete="ovl.hide();"
                         update="@form"/>
    </p:overlayPanel>
</h:form>

请注意,面板必须具有dynamic="true",因为必须在实际应用程序中获取动态内容,并且需要update="@form"才能更新其他表单组件。

问题是:如果我同时拥有属性,dynamic="true"update="@form",则叠加层仅在第一次显示。单击“关闭”按钮后,如果我再次单击“打开覆盖”,则面板将不会显示。

我究竟做错了什么?

(使用PrimeFaces 3.5和GlassFish 3.1.2.2)

jsf-2 primefaces
3个回答
13
投票

在按钮下降onclick="widgetVar.loadContents()"使用overlaypanel,其中widgetVaroverlayPanel的变量。


0
投票

我在下面的代码中注意到的是,只要在包含Open-Overlay按钮的表单上进行更新,它就会中断。

<h:form>
    <p:commandButton id="button1" value="Open overlay" type="button"/>
    <p:commandButton value="break things" update="@form" />
    <p:overlayPanel for="button1" dynamic="true">
        <p:commandButton value="Close" update="@form" />
    </p:overlayPanel>
</h:form>

如果可以将表单拆分为两个,嵌入在OverlayPanel中的按钮可以尝试调用单击用于切换叠加层的按钮。也许符合下面的内容。

<h:form>
    <p:commandButton id="button1" value="Open overlay" type="button"/>
    <p:overlayPanel for="button1" dynamic="true" >
        <p:commandButton value="Close" update=":formToBeUpdated" onclick="document.getElementById('button1').click();"/>
    </p:overlayPanel>
</h:form>

<h:form id="formToBeUpdated">
    <h:inputText value="bleh"/>
</h:form>

0
投票

你应该给你的overlayPanel一个id和oncompelete你的按钮显示它。代码如下:

<h:form>
   <p:commandButton id="button1" value="Open overlay" type="button" oncomplete="PF('ovlID').show()"/>
   <p:overlayPanel id="ovlID" for="button1" widgetVar="ovl" dynamic="true">
      <p:commandButton value="Close" oncomplete="ovl.hide();"
                     update="@form"/>
   </p:overlayPanel>
</h:form>
© www.soinside.com 2019 - 2024. All rights reserved.