Announcement

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

    Get Record from DataSource

    I have a ListGrid on a page that is populated by a DataSource. I then want to select a record in the ListGrid and pass the entire DataSource as well as the selected record to a new page to populate a form with the selected record and use the data in the DataSource to perform some business logic.

    Is there a way to identify the selected record on the DataSource? Or to get a specific record from the DataSource?

    I can get the index of the selected row and pass it to my new page but I do not see anyway to get that record from the DataSource.

    listGrid is populated by the InnerDataSource

    Code:
    InnerDataSource ids = (InnerDataSource) datasource.getDataSource("ids");
    int rec = listGrid.getRecordIndex(listGrid.getSelectedRecord());
    MaintainInner maintInner = new MaintainInner(ids, rec);
    How do I get the record at "rec" from "ids" on my new page?

    #2
    Think of the DataSource as representing a database table. Database tables don't have a selection, just the grid viewing the table has a selection.

    You can get a specific record from a DataSource by just using fetchData() with the id of the record as criteria.

    As far as going to a new page, note, you want to avoid page transitions as much as possible in modern RIA applications, unless the page transition is to totally unrelated functionality. Splitting things into pages means all cached data and rendered components are lost.

    But if this is a totally separate application, you can pass the ids as URL parameters and then use fetchData() in the target page to retrieve the relevant records as the new application starts up.

    Comment


      #3
      I mislead you when I said a new page.

      I am actually launching a modal window. On that window I need the entire contents of the datasource to perform some business logic. But I only really want to edit, on a form, the selected record. So fetchdata will not work in this scenario.

      I noticed that getCacheData returns a Record []. Would an efficient way of getting a single record from the datasource be to call getCacheData and then use the index of the selected record to find the Record I want to update?

      Comment


        #4
        ?

        Again, fetchData() can fetch a single record if you use the record's unique ID in the criteria. But if it's just a modal Window, and you already have a record selected in the grid, then it's just getSelectedRecord() to get that record.

        Comment


          #5
          Let me try and clarify why I am trying to do this...

          I want to be able to access this modal window from multiple places.

          In some instances I will have the listGrid and could use getSelectedRecord.

          However I want to be able to access the same modal window from native code. In those instances I was thinking it would be best to create a datasource and pass it to the window with some identifier of the record that I want to update. I need the entire datasource because the window needs to perform some business logic.

          Since in both cases I will have a datasource I was trying to just retrieve the Record selected from the datasource. But I do not want to overwrite the data in the datasource as I need it for my business logic.

          Comment


            #6
            Once again, there is no notion of a "selected" record in a DataSource - see previous posts.

            Either you already have the Record, or you have a grid (in which case you call getSelectedRecord()), or you have an ID (in which case you can call fetchData() to get the record).

            Comment


              #7
              I may not understand fully what DataSource.fetchData does. Will it not overwrite the datasource with the newly fetched data (which would be a subset of what is in the datasource already that meets the criteria I pass)?

              Comment


                #8
                No, it does not.

                Again, think of the DataSource as similar to a SQL table. Using select on a table doesn't wipe it out.

                Cached data, retrieved *from* a DataSource, is held onto objects like ResultSet and ResultTree. In order to understand better, start with the docs for ListGrid.fetchData() and read through everything that it links to.

                Comment

                Working...
                X