Announcement

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

    ValueMap localization for SelectItem with PickListGrid is not working

    Hi
    after upgrade from 3.1p to 5.0p our localization of valueMaps is not working for the case of using selectItem with the ListGrid inside the picklist.

    The simplified logic (also can be found in attached file):
    Code:
     
    public Canvas getViewPanel() {
    
        final DynamicForm form = new DynamicForm();
        form.setWidth(500);
        form.setNumCols(4);
        DataSource testDS = new TestDS();
        localize(testDS, Languages.DE);
    
        form.setDataSource(testDS);
        SelectItem testSelectItem = new SelectItem(TEST_FIELD);
        SelectItemWithPickList testSelectItemWithPickList = new SelectItemWithPickList(TEST_FIELD2, true, false);
        form.setItems(testSelectItem, testSelectItemWithPickList);
    
        return form;
    }
    
    private void localize(DataSource testDS, Languages lang) {
        for (DataSourceField dsField : testDS.getFields()) {
            if (TEST_FIELD.equals(dsField.getName()) || TEST_FIELD2.equals(dsField.getName())) {
                Map<String, String> localizedValueMap = dsField.getValueMap();
                for (String id : localizedValueMap.keySet()) {
                    if ("1".equals(id)) {
                        localizedValueMap.put(id, lang == Languages.EN ? "one" : "ein");
                    } else if ("2".equals(id)) {
                        localizedValueMap.put(id, lang == Languages.EN ? "two" : "zwei");
                    }
                }
                dsField.setValueMap(localizedValueMap);
            }
        }
    }
    
    public class TestDS extends DataSource {
        public TestDS() {
            setID("testDS");
            DataSourceTextField testField = new DataSourceTextField(TEST_FIELD, "Test");
            DataSourceTextField testField2 = new DataSourceTextField(TEST_FIELD2, "Test");
    
            Map<String, String> valueMap = new HashMap<String, String>();
            valueMap.put("1", null);
            valueMap.put("2", null);
    
            testField.setValueMap(valueMap);
            testField2.setValueMap(valueMap);
    
            setFields(testField, testField2);
            setClientOnly(true);
        }
    }
    
    public class SelectItemWithPickList extends SelectItem {
        public SelectItemWithPickList(String name, final boolean multiple, boolean allowEmptyValue) {
            super(name);
            setMultiple(multiple);
            setAllowEmptyValue(allowEmptyValue);
    
            setPickListFields(getPickListFields());
            setPickListProperties(getPickListGrid());
        }
    
        public ListGridField[] getPickListFields() {
            ListGridField field = new ListGridField(getName(), 230);
            field.setShowHover(true);
            return new ListGridField[] { field };
        }
    
        protected ListGrid getPickListGrid() {
            ListGrid pickListGrid = new ListGrid();
    
            pickListGrid.setShowFilterEditor(getShowFilterEditor());
            pickListGrid.setBackgroundColor("#fff");
            pickListGrid.setCanReorderFields(false);
            pickListGrid.setCanFreezeFields(false);
            pickListGrid.setCanPickFields(false);
            pickListGrid.setCanGroupBy(false);
    
            return pickListGrid;
        }
    
        protected boolean getShowFilterEditor() {
            return true;
        }
    }
    Tested on showcases:
    https://www.smartclient.com/builds/S...rtgwt-3.1p.zip
    https://www.smartclient.com/builds/S...rtgwt-5.0p.zip

    Please, check it and let me know what you recommend.

    Thank you
    Matus
    Attached Files
    Last edited by matus_b; 9 Apr 2015, 03:46. Reason: Added nightly build versions

    #2
    It's invalid to modify DataSourceField definitions after DataSource.setFields() has been called. This has always been true, and the fact that it worked in limited cases in 3.1 was just a quirk of the implementation and not a supported behavior.

    You just need to rearrange your code so that the localized valueMap is applied to the DataSourceField *before* the call to DataSource.setFields().

    Comment


      #3
      Problem is that we are using datasources in xml format. I constructed datasource in code only for showcase purpose.

      Comment


        #4
        Same issue; you can't modify DataSource fields on the fly after the DataSource has been defined.

        In the case of programmatic construction, setFields() is the moment when the DataSource fields must be considered frozen and unmodifiable. In the case of a .ds.xml, it's the first time the DataSource is loaded.

        As far as how to change your code in this different circumstance, the Internationalization overview explains our recommended approach for .ds.xml internationalization (based on resource bundles).

        Comment

        Working...
        X