Sunday, October 31, 2010

ADF UI - Resetting or clearing form fields in ADF popup on clicking 'Cancel'

Sample UseCase: Suppose the popup has input form fields to enter data with say OK and Cancel buttons, and when the user enters data and clicks on 'Cancel' button, we need to close the popup and reset all values entered in the popup's fields. If you don't reset the values, if you invoke the same popup again, it'll show the same previously entered values in the form which is unwanted. So, how to show the popup without the previous values?

Solution:
1. Set popup's 'contentDelivery' property to 'lazyUncached'. Setting this property won't cache the data entered and won't restore the previously entered values. This is highly recommended to set contentDelivery="lazyUncached" for better performance as the popup will be loaded only on invocation but not at the time of page loading.
<af:popup id="popup1" binding="#{pageFlowScope.ClassSectionCreateBean.cancelWarningPopup}" contentDelivery="lazyUncached">


2. If the step1 doesn't work, drop af:resetActionListener as a sub-element to 'Cancel' button in the popup. ResetActionListener will reset the form fields in the popup. We can also call ResetActionListener programmatically in an actionlistener method as follows using Oracle's internal API.
public void saveSections(ActionEvent ae) { //Your logic here ResetActionListener ral = new ResetActionListener(); ral.processAction(ae); }


But, using internal API in the code is not encouraged. There is public API to achieve the same using the below code.
UIComponent comp = actionEvent.getComponent(); oracle.adf.view.rich.util.ResetUtils.reset(comp);


But, this Public API is not yet available in the latest publicly available Jdeveloper available and it'll be available in the upcoming versions. Until then, we need to go ahead using internal API only as shown in step2.

15 comments:

  1. Helped me like anything..thanks :)

    ReplyDelete
  2. You cannot add a resetActionListener to a popup and secondly, if you have a dialog inside the popup, you NEED TO have a actionListener to the dialog, else there will be a NullPointerException thrown when the popup is shown up (processAction is called internally if done declaratively and as processAction of ResetActionListener needs ActionEvent as a parameter).

    ReplyDelete
  3. @Pavan: I mentioned that we can use af:resetActionListener as a sub-element to the 'Cancel' button to reset the fields in the form elements in the popup on clicking 'Cancel'. So, when the same popup is launched again, the previously entered values won't appear gain. The same could be achieved programatically using ResetUtils public API.

    And, when the dialog is inside the popup, there is no necessity to have the listeners defined. I'm not really clear why a NPE will be thrown without a listener.

    ReplyDelete
    Replies
    1. Hi Murali,

      I have an LOV in a popup and both contentDelivery="lazyUncached" and have failed to reset the LOV. Any thoughts on that?

      Delete
    2. Hi Remya,

      I am facing the same issue. Was the issue resolved?

      Thanks
      Swetha

      Delete
  4. I have 3 LOVs in my popup, and I am using the 'Ok' and "cancel' buttons that come with the dialog box. Out of the 3 LOVs, 3 rd LOV is dependent on the 1st LOV, and so it has a view accessor. The other 2 LOVs have no view accessors. I notice that on 'Cancel' and relaunch , the 3rd LOV i.e the one which has view accessor always shows blank, where as the other 2 independent LOVs render the right values. Is there any workaround to reset the LOV values on Cancel.
    In the Cancel logic, I tried re-executing the VA query and did a PPR on the LOV, but has no impact.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. On cancel the reset functionality is working perfectly fine. But when I click on OK button and save some data and try to open the popup , the form inside the popup is holding the previous set of field values.

    ReplyDelete

Related Posts with Thumbnails