Announcement

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

    Problem with SelectItem

    I am trying to implement a SelectItem bound to an xml.ds datasource. The select list displays correctly, however when I select and item from the list or change the selection, I am having difficulty assigning a value from the selected record to a field in the current form. I am following the pattern from the "Selected Value" item from the Showcase:

    Here is my code

    final SelectItem vendSI = new SelectItem();
    vendSI.setTitle("Vendor");
    vendSI.setPickListWidth(250);
    vendSI.setOptionDataSource(vendors);
    vendSI.setDisplayField("vendName");
    vendSI.setSortField("vendName");
    vendSI.setValueField("vendorName");
    catItemForm.setItems(vendSI);

    vendSI.addChangeHandler(new ChangeHandler() {
    public void onChange(ChangeEvent event) {

    catItemForm.setValue("vendName", event.getValue());
    }
    });

    In Eclipse this code throws and error that "event.getValue() is an object and cannot be assigned to a String (event.getValue() does not have to be cast to be assigned to a string) . If I cast event.getValue() to string, there is no returned value.

    Finally, ultimately, I would like to assign two values from the optionDataSource to the catItemForm. What is the best way to do this?

    Thank you for your help.

    #2
    If you want more than one value from the loaded record, use getSelectedRecord() to get the record. However if getValue() is not working, this suggests that your code is delivering something other than an atomic value for the "vendorName" field - take a look at the response data as shown in the RPC tab in the Developer Console to see if there's something wrong with the values for this field.

    Comment


      #3
      Thank you for your response. The answer to my first question was twofold. First, as you suggested, there was a conflict with the vendorName field. . .it was delivering more than one value. Second, the changeEvent that Eclipse suggested for import was not the correct import and resulted in the event.getValue() returning an object rather than a string. Once I copied and pasted out of the showcase sourcecode, this was fixed.

      Comment

      Working...
      X