SelectItem question

Hi,

I use a DynamicForm with many SelectItems on it. Each has the same OptionDataSource but differ with PickListCriteria.
My datasource contains unique values if you call fetch with the PickListCriteria. Otherwise not.

I try to preset a selected value by selectItem.setValue(value);
I receive a following exception and the result is as warned in the exception.

Is there any way how to turn on PickListCriteria for deriving valueMap?

[ERROR] [smartrise] - 15:26:47.298:XRP6:WARN:fetchMissingValues:isc_SelectItem_17:Deriving valueMap for 'value' from dataSource based on displayField 'displayText'. This dataSource contains more than one record with value set to ODP3 with differing displayText values. Derived valueMap is therefore unpredictable.

I use the official SmartGWT 2.5 release.

best regards,
Martin Zdarsky

Sounds like you are somehow forcing the entire DataSource to be loaded (without optionCriteria). Can you tell how you are doing this?

Hi,

thanks for a quick reply.
My form is drawn based on data in database. I fetch information about SelectItems through RPC call then I create the form and draw it.

If I leave out sitem.setValue(value); then the code behaves as expected. Correct SelectItems are drawn with correct values in it.

items = new ArrayList<FormItem>();
if (oList != null) {
	for (LinkedHashMap<String, String> map: oList) {
		final String answerId = map.get("answerId");
		String questionName = map.get("questionName");
		String displayText = map.get("displayText");
		String value = map.get("value");
		SelectItem sitem = new SelectItem(questionName, displayText);
		sitem.setOptionDataSource(DataSource.get("tdAnswerenumDS"));
		Criteria criteria = new Criteria();
		criteria.addCriteria("answerId", answerId);
		sitem.setPickListCriteria(criteria);
		sitem.setValueField("value");
		sitem.setDisplayField("displayText");
		sitem.setAlwaysFetchMissingValues(true);
		if (value != null) {
			sitem.setValue(value);									
		}
		sitem.setWidth(300);
		sitem.setDisabled(!canEdit);
		sitem.addChangedHandler(itemChangedHandler);
		items.add(sitem);
	}
}
questionnaireListForm.setFields(items.toArray(new FormItem[items.size()]));

This doesn’t give us any more information than before.. calls such as DataSource.setCacheAllData() or DataSource.setClientOnly() will cause a complete fetch of all data from the DataSource, which would expose the fact that your returned values aren’t unique when optionCriteria is omitted. Other than that, if you think there’s a bug or limitation here, please provide some code we can run to see the problem.

Hi,

I have prepared a test case using clientOnly DataSource.
A video with symptoms can be seen at www.zdary.cz/datasource_error.wmv

best regards,
Martin Zdarsky

branch.data.xml (1.03 KB)

ClientOnlyDS.java (1.34 KB)

Testcase.java (2.89 KB)

Thanks for putting this test case together.

Can you confirm: there is no functional problem, but you’d like to get rid of the warning?

No,

there is a function error. The display text is unpredictable and often wrong.

See the video. For the third SelectItem there are 3 record available from the dataSource:

ODP1 -> text7
ODP2 -> text8
ODP3 -> text9

this is correct.

Then I set SelectItem.setValue(“ODP3”); I expect to see a displayText “text9” but the selectItem renders “text3” which is a record for the first SelectItem ODP1 -> text3.

Looking at your code we realize the (first) problem is that the ‘pickListCriteria’ are being set rather than the ‘optionCriteria’ - this is not actually a synonym - optionCriteria govern the fetch to get the display-value mapping for the selected value whereas pickListCriteria govern the set of options to be displayed in the items pickList.
In most cases these will be the same, and indeed the criteria applied to the pickList are derived by combining both these values by default, but having separate properties allows developers to separate these and (for example) show a subset of options in the pickList.

However - as you no doubt saw, switching to optionCriteria you hit another bug - the pickList only shows a single option (the selected value). This is a framework issue which we have now resolved. The fix will show up in the next nightly build (dated September 15th or greater).

Let us know if you continue to have trouble with this

Thanks
Isomorphic Software

Hi,

this solved my problem. The value is rendered correctly.
I run into another problem which I believe is related to this fix.

I use SelectItem.getValue() for fetching data elsewhere. So I create criteria

Criteria.addCriteria("HOP110", SelectItem.getValue());

I expect “ODP1” as String from SelectItem.

When running in development mode in eclipse everithing is fine. RPC looks good.

{
    "dataSource":"dataUploadDS", 
    "operationType":"fetch", 
    "operationId":"manualDataEditSave", 
    "data":{
        "rawdataId":3, 
        "elementId":12, 
        "employeeId":157, 
        "branchId":5, 
        "applicationId":"2011029340", 
        "HOP110":"ODP1"
    }
    ...
}

However, when I run it in compiled mode in Tomcat version 6.0.x on both linux or windows the RPC looks wrong

{
    "dataSource":"dataUploadDS", 
    "operationType":"fetch", 
    "operationId":"manualDataEditSave", 
    "data":{
        "rawdataId":3, 
        "elementId":12, 
        "employeeId":157, 
        "branchId":5, 
        "applicationId":"2011029340", 
        "HOP110":{
            "0":"O", 
            "1":"D", 
            "2":"P", 
            "3":"1", 
            "java_lang_Object_castableTypeMap$":{
                "1":1, 
                "163":1, 
                "165":1, 
                "167":1
            }
        }
    }
    ...
}

This leads to ClassCastException serverside since I expect String and get org.apache.commons.collections.map.LinkedMap

tested with smartGWT 3.0 19-09-2011

best regards,
Zdary

This is due to a bug in core GWT where Strings can sometimes become “String Objects”. Usually what you need to do is remove an explicit call to toString() on something which is already a String.