6 Replies Latest reply: May 7, 2012 2:28 AM by in the line of fire RSS

    Comparing 2 instances of Same VO

    in the line of fire
      Experts,

      I have one VO with 2 instances in my AM. Say one is CustomerMaster and the 2nd one is UpdatedCustomerMaster. In my page i am displaying CustomerMaster as a read only form and UpdatedCustomerMaster as an Updateble form.

      My use case is to allow users to up allow users to update the values in the Updateable form and i need to compare the values with the values in the read only form. However my problem is since both are the current row of the same VO, they contain the same value

      Here is the code snippet i have written to do it but is failing :(
           // This method is defined in a custom class which extends ViewRowImpl 
          public Map compareTo(Row rowToCompare){
              HashMap returnMap = new HashMap();
              String currentObjectName = this.getViewObject().getName();
              if(rowToCompare!=null && rowToCompare instanceof CustomerMasterVORowImpl){
                  String[] name = this.getAttributeNames();
                  Object[] value = this.getAttributeValues();
                  String[] rowToCompareAttributeNames = rowToCompare.getAttributeNames();
                  Object[] rowToCompareAttributeValues = rowToCompare.getAttributeValues();
                  for (int i=0; i< this.getAttributeCount();i++)
                  {
                      logger.info(currentObjectName + " attribute : " + name);
      logger.info(currentObjectName + " value[i] : " + value[i]);
      logger.info("rowToCompareAttributeNames[i] : " + rowToCompareAttributeNames[i]);
      //logger.debug("Column name is " + getEntityAttrForAttribute(rowToCompareAttributeNames[i]).getColumnName());
      logger.info("rowToCompareAttributeValues[i] : " + rowToCompareAttributeValues[i]);
      if (rowToCompareAttributeValues[i] != null && value[i]!=null)
      if(!rowToCompareAttributeValues[i].toString().equals(value[i].toString())){
      returnMap.put(getEntityAttrForAttribute(rowToCompareAttributeNames[i]).getColumnName(), rowToCompare.getAttribute(name[i]).toString());
      logger.info("Addded " + getEntityAttrForAttribute(rowToCompareAttributeNames[i]).getColumnName() + " with value " + rowToCompare.getAttribute(name[i]).toString() + "in the map");
      }
      if (rowToCompareAttributeValues[i] != null && value[i]==null){
      returnMap.put(getEntityAttrForAttribute(rowToCompareAttributeNames[i]).getColumnName(), rowToCompare.getAttribute(name[i]).toString());
      logger.info("Addded " + getEntityAttrForAttribute(rowToCompareAttributeNames[i]).getColumnName() + " with value " + rowToCompare.getAttribute(name[i]).toString() + "in the map");
      }
      }
      return returnMap;
      }
      return returnMap;
      }



      My AM impl custom class calls this as below
              CustomerMasterVORowImpl customerMasterVoRow = (CustomerMasterVORowImpl)customerMasterVo.getCurrentRow();
              CustomerMasterVORowImpl updatedCustomerMasterVoRow = (CustomerMasterVORowImpl) updatedCustomerMasterVo.getCurrentRow();
              HashMap returnedMap = (HashMap)customerMasterVoRow.compareTo(updatedCustomerMasterVoRow); 
      Please advise.

      thnks
      Jdev 11.1.1.5
        • 1. Re: Comparing 2 instances of Same VO
          Dimitris Stasinopoulos
          Hi,

          To me, this seems to be quite normal since you are sharing the same transactions and thus AM.

          It is not clear to me when you are actually performing the checks. Can you please elaborate a bit more on that?


          You could use different AM, or regions for that matter..
          perhaps different AM would be a lot easier since with isolated BTF you would have to communicate with events.

          Here are some links that migh help you:

          http://one-size-doesnt-fit-all.blogspot.com/2011/05/jdev-11g-task-flows-adf-bc-always-use.html
          http://docs.oracle.com/cd/E21764_01/web.1111/b31974/taskflows_complex.htm#CHDDDFHA
          http://andrejusb.blogspot.com/2008/05/adf-task-flows-managing-transactions.html

          Hope this helps,
          Regards,
          Dimitris.
          • 2. Re: Comparing 2 instances of Same VO
            in the line of fire
            I have to check with the changes the user has done. For eg . If 10 attributes are editable by the user i want to know the attributes that the user has changed along with their values.
            Sample screen shot is attached here http://www.2shared.com/photo/knM3fnbr/issue.html
            My region has a splitter showing the data from the 2 instances of the same VO. So i cannot use different AMs here (at least with my least knowledge).
            • 3. Re: Comparing 2 instances of Same VO
              Dimitris Stasinopoulos
              Hello,

              Then, in this case, perhaps you could use the getPostedAttribute() method in your Entity java class.

              http://docs.oracle.com/cd/E21764_01/apirefs.1111/e10653/oracle/jbo/server/EntityImpl.html#getPostedAttribute_int_

              (overrides doDML)
              http://adfcodebits.blogspot.com/2010/07/bit-22-using-getpostedattribute-to.html

              (ofcourse be careful with doDML)
              how can i programatically update row

              (overrides prepareForDML example)
              http://jobinesh.blogspot.com/2010/12/updating-supporting-business-data.html


              The above link just show an implementation.. You should be able to determine when you will invoke these checks.

              Another case might be to use Groovy
              http://one-size-doesnt-fit-all.blogspot.com/2009/11/adf-bc-groovy-showing-old-values-along.html
              http://andrejusb.blogspot.com/2009/11/groovy-validation-hint-in-oracle-adf.html

              Still, it is not quite clear to me when you are going to fire those checks.. But hopefully the above links will help you
              Best Regards,
              Dimitris.
              • 4. Re: Comparing 2 instances of Same VO
                in the line of fire
                Hi,

                Ideally the page displays non editable data. Clicking on a button the data becomes editable. This is achievable as both are some different instances of the VO.
                Clicking on a 'SAVE' button then should check if the data in editable section is different from the non editable area.

                Hope i m clear this time.
                • 5. Re: Comparing 2 instances of Same VO
                  Dimitris Stasinopoulos
                  Hi, I think the above links might be helpful
                  Regards,
                  Dimitris.
                  • 6. Re: Comparing 2 instances of Same VO
                    in the line of fire
                    @Dimitris : Took a shot cut here.
                    Created a new EO and based a VO on it. And it worked.