问题
How can I show/hide the overlay panel conditionally from @ManagedBean based on some result.
In the below code: p:overlayPanel
is for p:commandButton
. I want to show overlay panel conditionally from Action method.
Right now it is showing every time I click the commandbutton.
<h:form id="form">
<h:outputLabel value="Town Name:"/>
<h:inputText value="#{myBean.town}"/>
<p:commandButton id="checkBtn" value="Check" action="#{myBean.action}"/>
<p:overlayPanel widgetVar="overL" id="over" for="checkBtn">
<h:outputText value="This town is not Listed in our records"/>
</p:overlayPanel>
</h:form>
Note : I'm using **Primefaces 3.5**
回答1:
Give the overlay panel a widget name and set showEvent to none (this kills the default behavior and assign a javascript handle to the panel):
widgetVar="myOverlay" showEvent="none"
add oncomplete attr to you button, something like:
oncomplete="if(args && !args.validationFailed) myOverlay.show();"
来源:https://stackoverflow.com/questions/18333219/conditional-display-of-poverlaypanel