Announcement

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

    does not show multiple values in expanded ListGrid's SelectItem editor

    Using Smart GWT 3.1 with Chrome 24.0.1312.57

    Please, see the example: http://www.smartclient.com/smartgwt/showcase/#grid_custom_editing_cell

    The SelectItem editor works fine with 'Dog' as on example's source code.

    But if I change the code that defines initial value "Dog,Goat" I will see it in the editor line, but if I expand the editor's comboboxes, nothing has been selected.

    private ListGridRecord[] getData() {
    return new ListGridRecord[]{
    new NameValueRecord(1, "String Editor", "some string"),
    new NameValueRecord(2, "Password Editor", "donkeykong"),
    new NameValueRecord(3, "Date Editor", new Date()),
    new NameValueRecord(4, "Boolean Editor", Boolean.FALSE),
    new NameValueRecord(5, "Masked Int Editor", 5),
    new NameValueRecord(6, "SelectItem Editor", "Dog,Goat"),
    new NameValueRecord(7, "Slider Editor", 7)
    };
    }

    How should I provide the initial values to have all of them to be selected?

    #2
    You need to set the SelectItem to be multiple, and then you provide the value as an array of String.

    Comment


      #3
      Thank you.

      Its already multiple within the original code.

      I tried to do the next:

      case 6:
      SelectItem selectItemMultipleGrid = new SelectItem();
      selectItemMultipleGrid.setShowTitle(false); selectItemMultipleGrid.setMultiple(true);
      selectItemMultipleGrid
      .setMultipleAppearance(MultipleAppearance.PICKLIST); selectItemMultipleGrid.setValueMap("Cat", "Dog",
      "Giraffe", "Goat", "Marmoset", "Mouse");
      selectItemMultipleGrid.setValues(new String[] {"Goat", "Dog"});

      Such lines work fine for regular SelectItem, but do not work if its an editor of the ListGrid.

      Comment


        #4
        Calling setValues() on something passed to listGridField.setEditorType() does not make sense - the values come from each ListGridRecord as it is edited, not from the (singular) call to setEditorType.

        So if a Record contains an attribute that is an Array of String, that will display in the multiple SelectItem as expected.

        Comment


          #5
          Now I tried:

          new NameValueRecord(6, "SelectItem Editor", new String [] {"Dog", "Goat"}),

          instead of

          new NameValueRecord(6, "SelectItem Editor", "Dog"),

          But now it shows something like "[Ljava.lang.String;@fbfb76f" in the TextField and does not select anything in the expanded comboboxes.

          I think it tries to apply the array of strings to setValue(), but not to setValues() as it was stored using the setAttribute("value", value). What the correct attribute name I need to use?

          Comment


            #6
            This is basically an artifact of the trivial NameValueRecord class used to create sample data. Constructing the Record directly using setAttribute() would bind to the DataClass setAttribute() method that takes a String[] and handles this properly.

            This also won't happen with actual databinding (RestDataSource, etc).

            Comment


              #7
              Can you elaborate your answer a little bit, please?

              What attribute name does it need to store the String[] value?

              Comment


                #8
                The name is not the problem and is already correct. Calling the right signature of setAttribute() is important.

                Comment


                  #9
                  The constructor calls the next function:

                  setAttribute("value", value);

                  What is the problem with it?

                  Comment


                    #10
                    This is a subtlety of Java method overloading.

                    In the scope of that setAttribute() call, the variable "value" is of Object type, therefore the signature of setAttribute() being called is the one with Object as the declared type of the parameter.

                    Switching over to a direct call of setAttribute() passing a String[] calls a different signature of setAttribute() - one with a String[] as the declared type of the parameter.

                    This conveys something different to the framework - whether you are trying to pass us a String[] vs whether you are trying to pass us an Object which is supposed to be treated as an opaque value.

                    Comment


                      #11
                      Thank you very much! Great explanation!

                      Comment


                        #12
                        Thank you so much!

                        Comment

                        Working...
                        X