4 Replies Latest reply: May 13, 2013 3:26 AM by Manish RSS

    ADF table:Remove Current Row.

    Manish
      Hi All,

      i'm using jdev 11.1.1.5.0

      In my use case i have created one adf table and a button which remove current selected row. in my adf table which is based on vo have Sno field that contain value like 1,2,3 accroding to row no.
      so suppose user remove 2 row then 3 row sno no set to 2 for this purpose i have written this code.
          public void removeRow()
          {
                  ViewObject detvo = getServicelib().getView("FaPmntTaDetView3Iterator");
                   Row detrow= detvo.getCurrentRow();
                    detrow.remove();
                    
                   long count = detvo.getEstimatedRowCount();
                   Row udetrow=null;
                   
                   
                        for(int i=1;i<=count;i++)
                        {
                            if(i==1)
                            {
                              udetrow=detvo.first();
                                }
                            else
                            {
                                udetrow=detvo.next();
                                
                                }
                         
                            udetrow.setAttribute("Sno",i);
                           
      }
              }
      problem is that above code remove last row table in place of current row but when i comment for loop code it is runnning fine but it is important to update sno .
        • 1. Re: ADF table:Remove Current Row.
          Timo Hahn
          Manish,
          this is a kind of use case you should not implement at all!
          There will be problems if you do so in a multi user environment. Think about what happens if tow or more users delete a row. Now you get duplicate sno attributes. If sno is a key attribute you are getting into trouble even more as you end up with duplicate keys.
          If you need to show rownumbers you can do so without storing the number in the row itself (e.g. with an EL like #{row.index}).
          The code you posted uses code which we can't see
                      ViewObject detvo = getServicelib().getView("FaPmntTaDetView3Iterator");
          I assume that you try to get the vo the table you see in the UI is based on. However, you propably get a fresh one and the current row for this vo is not the one you have set in the UI
          Instead you should use the iterator from the bindings and use it remove the current row like
          ...
                  BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
                  //access the name of the iterator the table is bound to. Its "YOURITERATORNAME"
                  //in this sample
                  DCIteratorBinding dciter = (DCIteratorBinding)bindings.get("YOURITERATORNAME");
                  dciter.removeCurrentRow();
          ...
          Timo
          • 2. Re: ADF table:Remove Current Row.
            Manish
            Hi timo,
                    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
                    //access the name of the iterator the table is bound to. Its "YOURITERATORNAME"
                    //in this sample
                    DCIteratorBinding dciter = (DCIteratorBinding)bindings.get("YOURITERATORNAME");
                    dciter.removeCurrentRow();
            i have already tried this but same result and sno is a part of primary key in my vo.
            and in my use case user also create row, for example add two three row on table and after that realized and want to any row which is created by user.

            i don't understand why code remove last row. i have also debug my code and i got current row. but result is delte last row not current.
            i think loop which i have run and it move the current row to last one using vo.next() but i have delete current row before loop.
            is it bug?

            Please provide me any solution for this scenario.
            • 3. Re: ADF table:Remove Current Row.
              Timo Hahn
              Let me try again:
              You should not edit a primary key or part of a primary key!

              This leads to all kind of problems. This one you see is only one of many to follow.

              Timo
              • 4. Re: ADF table:Remove Current Row.
                Manish
                Try to explain

                i have created master-detai insertion form(travel bill apply) where user create new record

                master table contain primary key applyno and detail table contain composite primary key (applyno,sno).

                master table contain detail of employee and location of tour and detail table contain expense detail so when user apply for tour it enter multiple entry on detail table using add record button so i have created sno accroding to row no if user create first row on detail then 1 after creating rows on detail user realize that created wrong and don't want particular row so use remove buton to remove current selected row.

                but as timo say
                You should not edit a primary key or part of a primary key!
                so how can i create row on detail table also i have not break series sno no like 1,3,4 on database.