Friday 18 November 2011

ADF - How to do partial rollback for changes done inside a PopUp on Cancel.

Time to move back to ADF. In this post I put down how to do a partial rollback of changes done in a popup on popup cancel and leave the other changes in the page which are not committed. When you have a save button at the page level, and in the page if you have an editable popup and now if the user opens the popup and changes something in it and clicks on Cancel in the popup we need to just revert the changes done in the popup and all the other changes done in the page should be left as it is.

How to do it.. Here we go.

1) When the popup is launched it should always take the value from the base attribute. So we need to set the ContentDelivery of the popup to lazyUncached
2) When the popup is launched we need to create a savePoint so that if its cancelled we can rollback to this point. Following steps help you to do this..
  • Associate an actionListner for the action component used for launching the popup
  • Since we invoke popup and also want this actionListener to be called at the same time, we need to set the showPopupBehaviour's TriggerType as Click. If you set the TriggerType as Action then ActionListener will not be called.
  • Have the following helper methods to create, delete and reset the SavePoint

        public void createSavePoint() {
            DCBindingContainer bindingContainer = ADFUtil.getDCBindingContainer();
            DCDataControl dcDataControl = bindingContainer.getDataControl();
            String spID = (String)dcDataControl.createSavepoint();
          AdfFacesContext.getCurrentInstance().getPageFlowScope().put("SavePointId",
                                                                        spID);
        }


    public void restoreSavePoint() {
        String spID =
            (String)AdfFacesContext.getCurrentInstance().getPageFlowScope().get("SavePointId");

        DCBindingContainer bindingContainer = ADFUtil.getDCBindingContainer();
        DCDataControl dcDataControl = bindingContainer.getDataControl();
        dcDataControl.restoreSavepoint(spID);
    }


    public void removeSavePoint() {
        AdfFacesContext.getCurrentInstance().getPageFlowScope().put("SavePointId", null);
    }

  • In the actionListener method you need to call the createSavePoint method. 
  • In the popupCancel action call restoreSavePoint method.
  • On click of Save button you need to remove the savePoint by clearing out the SavePointId in the pageFlowScope(I could not see a better way of deleting the savePoint). So you need to call removeSavePoint method on click of Save or in the DialogListeners OK OutCome.
Thats all we need to do for implementing RollBack for changes done in the popup. All the Change done in the base page will persist.

1 comment:

  1. Thanks for the post
    I have followed the steps now it is working properly but I have an issue, the row is getting disappeared once we have completed with the steps
    and when i reopen the popup the changed value is only being shown.

    ReplyDelete