Announcement

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

    Unexpected DataSourceField inheritance into the corresponding DynamicForm FormItem

    In the context of a RestDataSource I define one of the DataSourceFields this way:
    Code:
    DataSourceTextField currencyField = new DataSourceTextField("currency", "Currency code");
    currencyField.setCanEdit(true);
    currencyField.setEditorType(currencyItem);
    And then I bind a list grid component to this data source, let's call this data source the "main data source".
    The main data source fetches from the server side a list of records representing financial assets. So each record represents an asset, and one of the fields is the currency code, as show by the above code.
    To provide some light on the context, this field represents a country code string (such as "EUR" or "USD"... etc.)

    currencyItem is a form SelectItem whose values are fetched from another RestDataSource:
    Code:
    SelectItem currencyItem = new SelectItem("currency");
    currencyItem.setOptionDataSource(getCurrencyDataSource());
    Where getCurrencyDataSource() returns a fetch-only RestDataSource with a single DataSourceField text field that returns the currency code from the server-side.
    Let's call this secondary data source the "option data source".

    So when I bind my main data source to the list grid component, the elements in the "Currency code" column behave as expected, i.e. a select box comes up upon edition suggesting the right list of currency codes.
    See attached image SmartGWT_ListGrid.png.

    Now the unexpected behaviour occurs when I create a DynamicForm to edit the records coming out from the main data source.
    When I do that, the currency code field in the DynamicForm shows up as a select box and displays a list of currencies, but not the same list as the one coming up in the list grid.
    The currency codes list that show up in the DynamicForm is the list of currencies that belong to each asset listed in the list grid by the main datasource.
    See attached image SmartGWT_DynamicForm.png.

    And you can see that the list of currencies actually coming up in the DynamicForm's field is the sequence of the currencies listed by the main data source in the list grid when the list grid fetches the assets from the server.

    Adding the following code when creating the DynamicForm solves the issue:
    Code:
    DynamicForm form = new DynamicForm();
    form.setDataSource(dataSource);
    form.setUseAllDataSourceFields(true);
    form.setItems(currencyItem);
    Where dataSource is the main data source and currencyItem is the same currencyItem as the one described above in this post.
    Commenting the last line of this block produces the unexpected behaviour.
    So overriding the "currency" field with the same currencyItem does the trick, but expecting the same behaviour through DataSourceFields inheritance produces the unexpected listing of currencies as shown in the second attached image.

    Therefore my question:
    Why can I not just rely on inheritance in this case? Why do I need to override the DynamicForm field with basically the same item as the one used when defining the original DataSourceField it relates to? And when I say the same item... it is actually the same instance of the item.

    Any help would be much appreciated, apologies for the long question here, I hope this was clear enough.

    Regards,
    Luc
    Attached Files
    Last edited by dindeman; 2 Jun 2010, 18:22. Reason: Initially I posted twice the same attached image.
Working...
X