3

Is there a java command that can close a primefaces overlay panel? Or is there a way to make a button inside of an overlay panel close the panel when the button is clicked?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Landister
  • 2,194
  • 7
  • 38
  • 56

5 Answers5

6

You can easy add a button to your overlaypanel to close it e.g.

<p:overlayPanel widgetVar="myOverlayPanel" ... >
  <p:commandButton ... onComplete="PF('myOverlayPanel').hide(); ... />
</p:overlayPanel>

Also you can do this in Java

private void doSomething() {
  RequestContext ctx = RequestContext.getCurrentInstance();
  ctx.execute("PF('myOverlayPanel').hide();");
} 
Arthur Welsch
  • 269
  • 2
  • 15
  • This solution worked for me in PF 6.2, except that I had to use the `onclick` event instead of `onComplete`. – Jake Reece Feb 12 '19 at 20:28
1

I've found that (in PrimeFaces 7.0 at least) a p:commandButton that merely updates the form or any component outside the overlayPanel will close the overlayPanel. For example,

<p:commandButton value="Close" update="myform" />

My only concern is that I can't find documentation that explains specifically that or why this happens, so I'm a little hesitant to depend on it. On the other hand, it seems to do a cleaner job than onclick="PF('panelWidgetVar').hide();", which tends to blank my browser window and redraw the whole page, whereas update alone seems to refresh just those parts of the page I need updated.

Kevin Rahe
  • 1,609
  • 3
  • 19
  • 27
0

Put this inside p:overlayPanel tag and set p:effect 'for' attrib with overlayPanel id, use the appendToBody=true.

 <p:commandLink styleClass="ui-icon ui-icon-triangle-1-e">
        <p:effect type="slide"  for="idOverlayPanel" event="click">
            <f:param name="mode" value="'hide'"/>
            <f:param name="direction" value="'right'"/>
        </p:effect>
    </p:commandLink>

Without effect parameters

<p:commandLink styleClass="ui-icon ui-icon-close" >
    <p:effect type="slide"  for="idOverlayPanel" event="click"/>
</p:commandLink>

You can change slide effect to anotherone, icon style class too.

Sorry for my bad english

0

I have done this with jQuery and css. please check below code

<p:overlayPanel widgetVar="overlay" showEffect="blind" showCloseIcon="true" styleClass="lane-overlay" dynamic="true" dismissable="true" hideEffect="blind">
<script>
$(document).ready(function(){
$(".closeIcon").click(function(){
$(".lane-overlay").hide();
});
});
</script>
<p:commandButton value="close"  styleClass="closeIcon"/>
`enter code here`
Krishna Mohan
  • 1,503
  • 3
  • 22
  • 28
Sri
  • 1
  • 1
0

how about something like (haven't tested myself)

client side only solution

<p:commandButton id="basic" onclick="jQuery('#IdOfThePanel').hide()"></p:commandButton>

or client side + server side

jsf:

<p:commandButton value="Save" actionListener="#{myBean.doSomething}"/>

java:

public void doSomething(ActionEvent actionEvent) {

    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("jQuery('#IdOfThePanel').hide()");
}

take a look here on executing js from java

Executing Javascript from Server Side

p.s maybe instead of IdOfThePanel you'll have to add some prefix like formID:IdOfThePanel... depends on your case...

Edit: instead of jQuery('#IdOfThePanel').hide() just use panelWidgetVar.hide() or in more recent PrimeFaces versions, PF('panelWidgetVar').hide()

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Daniel
  • 36,833
  • 10
  • 119
  • 200