Thursday, 25 April 2013

Hello everybody!!

Today I am gonna discuss on an use-case where we want to show a  message on click of the close icon of a af:dialouge component .

The problem with this usecase is the popup discloserevent, It executes after immediatlly closing the popup window , Here I will show how to call your method before popup dismisses.

------------------------------------------------------------------------------------------------------------
Step 1: Paste this javascript in the Jsf page -


  <af:resource type="javascript">
      function onDialogCancel(evt){
  var outcome = evt.getOutcome();        
if(outcome == AdfDialogEvent.OUTCOME_CANCEL){
var eventSource = evt.getSource();
var immediate = true;
AdfCustomEvent.queue(
            eventSource,
"DialogCancelHandlerEvent",
{},immediate);
           evt.cancel();
             }
         }
      </af:resource>

Step 2- Inside the dialouge popup source code put the client and serverlistener code  -

  <af:popup id="demoPopup"

                       
              contentDelivery="lazyUncached"
              autoCancel="disabled">


 <af:dialog id="adl1"  >
--
--
--
--
--


 <af:clientListener method="onDialogCancel"
                                             type="dialog"/>
                          <af:serverListener type="DialogCancelHandlerEvent"
                                             method="#{demoBean.onDialogCancel}" />
</af:dialog>
</af:popup>
-------------------------------------------------------------------------------------------------------------
The af:serverListener calls the onDialogCancel event when user clicks on the close icon , inside the method we can put our own logic logic i.e  :


    public void onDialogCancel(ClientEvent clientEvent) {
   
        if (changesExists()) {
          // code to open a warning popup

         
        } else {
         // code to close the popup
        }
   
    }



  public static boolean changesExists() {
      DCBindingContainer bindings = ADFUtils.getDCBindingContainer();
      ApplicationModule am = bindings.getDataControl().getApplicationModule();
   
      return am.getTransaction().isDirty();
  }



0 comments:

Post a Comment