Announcement

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

    Issue on singleton instance for DataSource

    Dear Sir,

    We have a number of search and input combo box controls sharing the same DataSource object currently in our pages, e.g. Sub-fund selection combo box, and they are implemented in below way:

    — Code in class PageA —
    Code:
    private DataSource dsSubfund = DataSource.getDataSource("subfund");
    private StandardComboBoxItem cbSubfund = new StandardComboBoxItem("subfundCode1", "Subfund1");
    cbSubfund.setOptionDataSource(dsSubfund);
    cbSubfund.setSortField("subfundMnemonic");
    — Code in class PageB —
    Code:
    private DataSource dsSubfund = DataSource.getDataSource("subfund");
    private StandardComboBoxItem cbSubfund = new StandardComboBoxItem("subfundCode2", "Subfund2");
    cbSubfund.setOptionDataSource(dsSubfund);

    Now the problem is SmartGWT manages only one singleton object per data source ID, the method DataSource.getDataSource("subfund") will return the same singleton instance in all pages. This creates the conflict like, for example:
    Page A is applying sort field "subfundMnemonic' on the combo box, and Page B is not applying any sorting.
    But you will still see a sorted result in Page B's combo box if you have entered Page A before.

    Which means the DataSource filtering, sorting criteria will be corrupted by each other.

    There will be serious impact of redundancy if we declare individual data source for every combo box on each page, so we suppose this is the last approach we would like to take.

    We have also tried some method in DataSource class like .setCacheAllData(boolean cacheAllData), however they are not helping on the issue.

    It is highly appreciated if you could provide any way to get the 'prototype' instance of DataSource. Thanks very much

    #2
    You should be able to resolve this by calling setCachePickListResults(false); on your ComboBoxItems.

    The problem you're facing is not that the ComboBoxes are sharing a DataSource - this is actually correct architecture - a single DataSource should be able to provide data for multiple ListGrids, comboBoxItems etc.

    The problem is that by default ComboBoxItems (and SelectItems) will avoid redundent fetches by sharing the data they load from their optionDataSource across all instances attached to the same optionDataSource, and in your usage this is leading to odd behaviors like sorting being applied to this shared data set even for items where you don't want the data sorted. You can disable this sharing via the 'cachePickListResults' attribute, which should resolve your bad behaviors.

    FYI: There is logic in the framework to avoid this sort of collision but clearly you're hitting an edge case that isn't being handled cleanly. This may already have been resolved in the 3.0 branch, but regardless, this workaround should fix the issue for you. If you'd like us to look at this further we'd need to see a test case we can run on our end that reproduces the problem.

    Comment


      #3
      Dear Sir,

      We have checked this new API is only available in SmartGWT version 3.0:
      http://smartgwt.googlecode.com/svn/trunk/distro-source/core/src/api-changes.html

      Is there any another API or solution that is supported by version2.5 ? Since we will not upgrade to version 3.0 in short at the moment.

      Thank you very much.

      Comment

      Working...
      X