Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    To get the records as such in the bean into the update method.

    Hi

    I have a listgrid displaying many records.

    1. In my listgrid say i have 10 columns.
    2. I have a java bean with these 10 attributes.
    3. In my DAO class after querying the database i populate the resultset into arraylist of bean objects.
    4. I pass that arraylist to my manager class and set it in dsResponse.setData() method.
    5. Now on the screen all the records are displayed.
    6. Now if i edit few cells in a record and click on save then i should update the database with edited values.
    7. In my update method in manager class, i will get all the edited values record by record using newValues Map.
    8. But the user can modify the cells in a record in any combination. Many combinations are possible. I can not generate the query dynamically to all the possible combinations. Its a tedious task.
    9. Is there any way i get the values of all the cells(edited and non-edited) of a particular record in the bean, so that i can pass that bean object to my DAO class and then update the database. In this case i can write only one update query.

    a simple example:
    on the screen the record displayed for the columns A,B,C and D is
    Code:
             A        B        C        D
           ------    -----  -----    -----
             1        2        3        4
    User edits few values(say 1 to 5 and 3 to 7) and before he clicks on save the listgrid looks like
    Code:
             A        B        C        D
            ------   -----  -----    -----
             5        2        7        4
    Now when he clicks on save, in my update method of manager class i should have bean object with attribute values: a->5, b->2, c->7, d->4

    so i will write a single update query

    Update TableT set A=5, B=2, c=7, d=4 where ............

    I thought i can achive this as mentioned below:
    in update method get old values of a record from listgrid using dsRequest.getOldValues(); write some logic to populate the bean with a mix of old and new values and then send that bean object to DAO class.
    If a listgrid has fewer columns then what i though might work out. Suppose if a listgrid has many columns(say >20) then i feel my approach is not the right one.

    How i can achive this in a best possible way.

    #2
    What is it that you feel is wrong with your approach? Too many columns being updated when only a few have changed? You seem to have all the appropriate data at your disposal to do the update in whatever way you want..

    Comment


      #3
      Hi Isomorphic

      What is it that I feel is wrong with my approach?

      Is it necessary to write custome code to populate a bean object with a mix of both edited and old values using oldValues Map and newValues Map.

      I was thinking can i use some method of listgrid where i can get the required data. After posting the question i found that the ListGrid.getEditedRecord() method returns the combination of unsaved edits (if any) and original values (if any) for a given row being edited.

      On click of save/update button i can call ListGrid.updateData(updatedRecord) method where updatedRecord = myList.getEditedRecord(getEditRow()).

      Now i want to know how my update method signature should be in my manager class and how the updatedRecord will be received in my manager class.

      Comment


        #4
        Combining two instances of java.util.Map into a single Map is an exceedingly trivial piece of Java code. That's all you need to do with the values and oldValues on the server.

        Comment


          #5
          This looks cool solution :) :).... It did not strike me... Thanks Isomorphic

          Comment

          Working...
          X