首页 > 解决方案 > 页面加载时显示 Primefaces 的 OverlayPanel

问题描述

overlayPanel当单击目标组件 (a ) 时,该页面会显示 Primefaces commandButton

<p:commandButton id="inputBtn" value="Choose a data source" type="button" action="#{dataImportBean.oAuth}"/>
 
<p:overlayPanel
 id="overlaypanel1"
 for="inputBtn"
 dynamic="false"
 widgetVar="inputChooser"
 >
// contents of the overlay panel
</p:overlayPanel>

我需要overlayPanel在页面加载时显示,而无需单击目标commandButton

用例是:用户已overlayPanel打开但 oAuth 流程使用户导航离开页面。oAuth 完成后,用户将被重定向到该页面。但是,当页面加载时,overlayPanel 会关闭,而我需要将用户直接带回 overlayPanel,以保持一致性。

标签: jsfprimefaces

解决方案


在您的小部件 var 上使用客户端 API。您可以使用show()来显示面板,因此在您的情况下:PF('inputChooser').show().

要在页面加载时执行此操作,您可以将其放在p:overlayPanel

<c:if test="#{yourCondition}">
<script>$(function() { PF('inputChooser').show() })</script>
</c:if>

也可以看看:


推荐阅读