0 Replies Latest reply: Jan 6, 2009 3:35 PM by 807575 RSS

    Getting at existing values when values submitted to CachedRowDataSetProvide

    807575
      I have a datatable that has a save button. I need to know how to tell if an existing row value in the DB/datatable has been altered, versus a new entry. the reason for this is when an existing entry is altered, I need to populate a field "UPDATE_ID" and "UPDATE_TIME" for the preexisting row that has been changed. I have set up a duplicate CachedRowDataSetProvider in order to do this, but this method does not work, you will see it commented out in my savebtnaction code below. I think I need to use a TableDataListener but Im not sure how to implement that in my code. Anyhelp is appreciated
      public String savebtn_action() {
              // TODO: Process the action. Return value is a navigation
              // case name where null will return to the same page.
              //Navigate through 
           java.sql.Timestamp dateToInsert = new java.sql.Timestamp(date.getTime());
              try {
                  //if (trnsfr_agentDataProvider.getRowCount() > 0){
                  //    trnsfr_agentDataProvider.cursorFirst();
                  //     
                  // }
                  SessionBean1 sessionBean = getSessionBean1();
                  Boolean namechange = false;
                  Boolean descrchange = false;
                  Boolean svrchange = false;
                  Boolean statuschange = false;
                  CachedRowSetDataProvider maxTransID = getSessionBean1().getMaxTrnsfrAgentIDDataProvider();
                  maxTransID.refresh();
       //          CachedRowSetDataProvider oldvalues = new CachedRowSetDataProvider();
       //           oldvalues = trnsfr_agentDataProvider;            oldvalues.refresh();
                  maxTransID.cursorFirst();
       //           java.math.BigDecimal num1, num2;
                  java.math.BigDecimal num1 = new java.math.BigDecimal(1L);
                  java.math.BigDecimal newTransId = ((java.math.BigDecimal) maxTransID.getValue("MAXTRNSFR_AGENTID"));
                  System.out.println("###### newTransID = " + newTransId);
                  if (newTransId == null){
                      newTransId = new java.math.BigDecimal(1L);
                  }
                  System.out.println("###### after null if comparison newTransID = " + newTransId);
               //   num1 = new java.math.BigDecimal(1.0000);
      //            num2 = new java.math.BigDecimal(-1.0000);
                   System.out.println("###### trnsfragentrowcount = " + trnsfr_agentDataProvider.getRowCount());
                  if (trnsfr_agentDataProvider.getRowCount() >= 0) {
       //               oldvalues.cursorFirst();
                     
                      trnsfr_agentDataProvider.cursorFirst();
                      
                      
                      do {
        //                if (trnsfr_agentDataProvider.getRowCount() != 0){
                          if (trnsfr_agentDataProvider.getValue("TRNSFR_AGENT_ID").equals(new Integer(0))) {
                              
                              trnsfr_agentDataProvider.setValue("TRNSFR_AGENT_ID", (java.math.BigDecimal) newTransId);
                              newTransId = newTransId.add(num1);
                              
       //                  } else {
                              //Checks old values in Database against possible new values...
        //                     if(!oldvalues.getValue("NM").equals(trnsfr_agentDataProvider.getValue("NM"))){
       //                           namechange = true;
        //                      }
       //                       if(!oldvalues.getValue("DESCR").equals(trnsfr_agentDataProvider.getValue("DESCR"))){
        //                         descrchange = true;
        //                     }
          //                   if(!oldvalues.getValue("SVR").equals(trnsfr_agentDataProvider.getValue("SVR"))){
          //                       svrchange = true;
          //                   }
           //                  if(!oldvalues.getValue("STATUS").equals(trnsfr_agentDataProvider.getValue("STATUS"))){
           //                      statuschange = true;
            //                  }
           //                 if(namechange == true || descrchange == true||svrchange == true||statuschange == true){
           //                      trnsfr_agentDataProvider.setValue("UPDATE_DT", dateToInsert);
           //                      trnsfr_agentDataProvider.setValue("UPDATE_USER_ID", (String) sessionBean.getUsername());
           //                      namechange = false;
           //                      descrchange = false;
           //                      svrchange = false;
           //                      statuschange = false;
           //                  }
           //                  oldvalues.cursorNext();
                          }
                          
                                        } while (trnsfr_agentDataProvider.cursorNext());
                      trnsfr_agentDataProvider.commitChanges();
                      trnsfr_agentDataProvider.refresh();
                  }      
              } catch (Exception ex) {
                  log("Error Description", ex);
                  error("Error :" + ex.getMessage());
              }
              return null;
          }