Jsf 2 Primefaces动态覆盖面板仅显示一次

Jsf 2 Primefaces动态覆盖面板仅显示一次,jsf-2,primefaces,Jsf 2,Primefaces,我有一个带有按钮的表单,可以打开PrimafacesOverlyPanel。 在面板中有另一个按钮,它执行Ajax操作,然后关闭覆盖。 下面是一个简化版本,完全没有Ajax操作: <h:form> <p:commandButton id="button1" value="Open overlay" type="button"/> <p:overlayPanel for="button1" widgetVar="ovl" dynamic="true"&

我有一个带有按钮的表单,可以打开Primafaces
OverlyPanel
。 在面板中有另一个按钮,它执行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)

我注意到下面代码中的内容是,只要您对包含“打开覆盖”按钮的表单进行更新,它就会断开

<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>

如果可以将表单一分为二,则嵌入覆盖面板中的按钮可以尝试调用用于切换覆盖的按钮上的单击。也许与下面的内容一致

<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>

使用
onclick=“widgetVar.loadContents()”
在下拉
OverlyPanel
的按钮中,其中
widgetVar
OverlyPanel

的变量。您应该给您的OverlyPanel一个id,并在完成按钮后显示它。 代码如下所示:

<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>


谢谢你,阿克塞尔。不幸的是,覆盖是在许多不同视图中使用的复合组件的一部分,因此它必须由父表单元素承载:它无法定义自己的表单,因为我最终会使用嵌套表单。谢谢它的工作。您是如何找到此方法的,它未在Primefaces用户指南中列出。更新:onclick=“PF('widgetVar')。loadContents();”