Announcement

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

    duplicate entries in my select distinct SelectItem

    Hi,

    I'm using SmartClient Version: v8.3p_2014-03-06/PowerEdition Deployment (built 2014-03-06) (SmartGWT 3.1p) with PostgreSQL 9.2.2, Firefox 26.0, and Tomcat 7.0.33.

    I have a SQL dataSource with a bunch of fields including a field called 'cycle'. The dataSource supports some listGrids and it also supports a SelectItem for the 'cycle' field. Since the 'cycle' field can have duplicates I defined a special operationBinding for the SelectItem which does a select distinct. The operation binding looks like:
    Code:
    <field name="cycle"    type="text"     title="Billing Cycle"  />
    ...
    <binding operationType="fetch" operationId="comboBoxCycleList" outputs="cycle">
           	<selectClause>distinct cycle</selectClause>
           	<orderClause>cycle</orderClause>
           	<whereClause>cycle is not null</whereClause>
    </binding>
    I define the SelectItem this way:
    Code:
    cycle = new SelectItem("cycle");
    cycle.setDisabled(false);
    cycle.setOptionDataSource(asdDS);
    cycle.setOptionOperationId("comboBoxCycleList");
    All this seems to work fine. I can see the dataSource entries in listGrids. I can add, edit and delete entries. I can access the SelectItem and see the distinct list of cycles.

    I have a problem with the SelectItem list if a entry is added to the dataSource with an existing cycle number. The add is done with the default add operation. It looks like the cache sync adds the cycle value from the new entry to the SelectItem list. This is done without any OptionDataSource fetch so my select distinct is not used and this gives me duplicates in the SelectItem list. (They are also not sorted.)

    I tried using a DataArrived handler on the SelectItem. My intent was to issue a new fetch for the SelectItem when the cache sync changed the list, but the handler wasn't called due to the cache sync.

    How should I fix this? Do I watch for data updates and refetch? If so, what handler do I use and on what object? Are there some settings which I need to use that I've missed?

    Am I on the right track or is there some other way to construct a distinct list for the SelectItem that will be updated without generating these duplicates?

    Thanks,
    Kevin

    #2
    A few options:

    1. set resultSet.disableCacheSync via pickListProperties -> dataProperties. This won't catch the case that a cycle is added or removed.

    OR

    2. watch for changes on the DataSource by creating a ResultSet with initialLength:0 and adding a DataChanged handler. Whenever data changes, tell the SelectItem to refetch

    OR

    3. create a separate DataSource which just has the "cycle" field you want, and calls the original DataSource to get data, via a trivial DMI. Use DSResponse.addRelatedUpdates() on the original DataSource to make sure this related DataSource gets updated when a cycle value is added or removed. This could be slightly more efficient than #2 because there is no re-fetch, but quite possibly this is not worth the trouble.

    Comment

    Working...
    X