Announcement

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

    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?

    Code:
    [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
    Last edited by zdary; 12 Sep 2011, 05:53.

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

    Comment


      #3
      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.

      Code:
      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()]));

      Comment


        #4
        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.

        Comment


          #5
          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
          Attached Files

          Comment


            #6
            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?

            Comment


              #7
              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.

              Comment


                #8
                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

                Comment


                  #9
                  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
                  Code:
                  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.
                  Code:
                  {
                      "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
                  Code:
                  {
                      "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

                  Comment


                    #10
                    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.

                    Comment

                    Working...
                    X