0

I have two primefaces panels in one form.

<p:panel id="pnlOne" widgetVar="pnlOne"> <p:ajax event="close" listener="#{createProduct.cancelAddProductCategory}"/></p:panel>'
<p:panel id=pnlTwo" widgetVar="pnlTwo"> <p:ajax event="close" listener="#{createProduct.cancelAddBrand}"/></p:panel>

I have another commandButton which will call the panel close function on its oncomplete attribute.

<p:commandButton id="btnadd" value="#{bundle.LabelSave}" update=":forminput :formcollector" 
action="#{createProduct.createNew}" oncomplete="handleComplete(xhr, status, args)">

I set the success callback parameter in the backing bean as follows;

RequestContext.getCurrentInstance().addCallbackParam("success", true);

And the javascript function handleComplete as below;

function handleComplete(xhr, status, args) {  
if(args.success) {  
    pnlOne.close();
    pnlTwo.close();
    } } 

The problem is only one of these two panel can be closed. My purpose is to close both successively. But it doesn't work. Could it be because the first close execution in the javascript trigger an ajax request, have not complete the ajax request by the time second panel close is called? Any idea guys. Your help is very much appreciated.

frazkok
  • 49
  • 1
  • 2
  • 11

2 Answers2

1
  1. set the visibility of both panels to "#{createProduct.showPanel}"

  2. update the showPanel to true or false in the createProduct bean.

  3. For the commandButton, have an update on both the panels.

rags
  • 2,580
  • 19
  • 37
0

This is how to solve this. Actually if the panel is not displayed by the user, and calling the close method for that invisible panel created the scenario above. So I just add.

If the method in my bean succeed and both panels are displayed:

RequestContext.getCurrentInstance().addCallbackParam("success", true);    
if (pnl1 is visible) {
    RequestContext.getCurrentInstance().addCallbackParam("pnlone", true); 
}
if (pnl2 is visible) {
    RequestContext.getCurrentInstance().addCallbackParam("pnltwo", true); 
}

JavaScript:

function handleComplete(xhr, status, args) {
  if(args.success) {  
      if (args.pnlone) {  
          pnlOne.close(); 
      }
      if (args.pnltwo) {  
          pnlTwo.close();
      } 
  } 
}  
frazkok
  • 49
  • 1
  • 2
  • 11