5 Replies Latest reply: May 9, 2012 12:19 PM by Sudipto Desmukh RSS

    Error Handling in Popup while Inserting record

    918966
      I am using JDeveloper 11.1.1.6

      My use case has a screen that displays data from a given table. On that screen I have an "add" button which when clicked gives the user a popup form in which they can add records. A copy of the popup is attached at the bottom. Here are a few notes on the fields in the popup:

      Field1 - part of Primary Key. It is prepopulated for the user so it is read only
      Field2 - part of Primary Key. User enters a value
      Field3 - not part of Primary Key, but is a required value (not nullable)


      The onAddRecordPopupFetchAction() in my backing bean performs a "CreateInsert".

      In the popup if I enter a value for Field2 that is valid (doesn't cause a duplicate key) and populate Field3, upon clicking OK I successfully enter the addRecordDialogOKAction() method in my backing bean.

      The problem I am having is if I enter a value for Field2 that is NOT* valid ( causes a duplicate key) and populate Field3, upon clicking OK I for some reason do not enter the addRecordDialogOKAction() method in my backing bean. Instead upon clicking OK, the app is determining that a duplicate key is causes and Field2 is highlighted with the error.




      <af:popup binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.addPopup}"
      id="addPopup" contentDelivery="lazyUncached"
      popupFetchListener="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.onAddRecordPopupFetchAction}"
      popupCanceledListener="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.onAddRecordPopupCancelAction}">
      <af:dialog id="addDialog" closeIconVisible="true"
      dialogListener="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.addRecordDialogOKAction}"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.addDialog}">
      <af:panelHeader text="My Page"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.ph2}"
      id="ph2">
      <af:panelFormLayout binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.pfl1}"
      id="pfl1">
      <af:selectOneChoice value="#{bindings.Field1.inputValue}"
      label="#{bindings.Field1.label}"
      required="#{bindings.Field1.hints.mandatory}"
      shortDesc="#{bindings.Field1.hints.tooltip}"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.soc2}"
      id="soc2" readOnly="true">
      <f:selectItems value="#{bindings.Field1.items}"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.si2}"
      id="si2"/>
      </af:selectOneChoice>
      <af:inputText value="#{bindings.Field2.inputValue}"
      label="#{bindings.Field2.hints.label}"
      required="#{bindings.Field2.hints.mandatory}"
      columns="#{bindings.Field2.hints.displayWidth}"
      maximumLength="#{bindings.Field2.hints.precision}"
      shortDesc="#{bindings.Field2.hints.tooltip}"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.it1}"
      id="it1">
      <f:validator binding="#{bindings.Field2.validator}"/>
      <af:convertNumber groupingUsed="false"
      pattern="#{bindings.Field2.format}"/>
      </af:inputText>
      <af:inputText value="#{bindings.Field3.inputValue}"
      label="#{bindings.Field3.hints.label}"
      required="#{bindings.Field3.hints.mandatory}"
      columns="#{bindings.Field3.hints.displayWidth}"
      maximumLength="#{bindings.Field3.hints.precision}"
      shortDesc="#{bindings.Field3.hints.tooltip}"
      binding="#{backingBeanScope.backing_ui_pages_Maintenance_viewMyPage.it2}"
      id="it2">
      <f:validator binding="#{bindings.Field3.validator}"/>
      <af:convertNumber groupingUsed="false"
      pattern="#{bindings.Field3.format}"/>
      </af:inputText>
      </af:panelFormLayout>
      </af:panelHeader>
      </af:dialog>
      </af:popup>
        • 1. Re: Error Handling in Popup while Inserting record
          Sudipto Desmukh
          That should be the correct behaviour as Listeners (method in DialogListener in your case) are fired after validations are processed in the ADF/JSF Lifecycle & only if the validations pass through fine else control jumps to render Response phase
          http://www.roseindia.net/jsf/jsflifecycle.shtml
          http://docs.oracle.com/cd/E15051_01/web.1111/b31974/adf_lifecycle.htm#CFHDGFEF

          Also see if putting immediate =true on the Field 2 helps.
          http://adfpractice-fedor.blogspot.in/2012/02/understanding-immediate-attribute.html
          • 2. Re: Error Handling in Popup while Inserting record
            918966
            I added immediate="true", but still got the same result
            • 3. Re: Error Handling in Popup while Inserting record
              918966
              Here is a little bit more information. The error I am getting is:

              "(oracle.jbo.TooManyObjectsException) JBO-25013: Too many objects match the primary key oracle.jbo.Key[199 1 ]."



              I already use MessageBundles to handle "JBO-26048 (DMLConstraintException)" exceptions. Sample code for that is shown below. I didn't include the resource bundle properties, but this does work. Ideally I think I would do something similar to handle JBO-25013's, but maybe I am off track. How might I best handle these?



              public class MyMessageBundle extends ListResourceBundle {

              private static final String BUNDLE_NAME =
              "com.jcc.common.model.MyModelBundle";

              private static final Object[][] sMessageStrings =
              new String[][] { { "TABLE1_PK", getTable1_PKMessage() },
              { "TABLE2_PK",
              getTable2_PKMessage() } };

              private static String getTable1_PKMessage() {

              ResourceBundle myBundle = ResourceBundle.getBundle(BUNDLE_NAME);
              return myBundle.getString("TABLE1_PK");

              }
              }

              Edited by: 915963 on May 9, 2012 8:52 AM
              • 4. Re: Error Handling in Popup while Inserting record
                918966
                I have figured out how to solve this using the resource bundle with 1 issue remaining. Here is what I have added to the resource bundle.

                25013=The ?????? field is not unique.


                The question I have is, 'is there anyway to replace the ?????? with the actual field name'?
                • 5. Re: Error Handling in Popup while Inserting record
                  Sudipto Desmukh
                  You can add it as a EO level Unique validation and add tokens as mentioned
                  7.7.1 How to Associate Error Messages with Oracle ADF Entity Object Validation Rules under
                  http://docs.oracle.com/cd/E25178_01/fusionapps.1111/e15524/bs_messages.htm#DIECJJCD