Announcement

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

    Set SelectItem programmatically

    Scenario:
    A SelectItem connected to a DataSource (viewSelectorItem.setOptionDataSource(myDS)):
    On relogin, the last selected SelectItem should be restored.
    The ID of the selected Item is saved in a cookie.
    Unfortunately, SelectItem.getViewState() does not exist for SelectItem or the Form it is embedded in (someForm), so there must be another way to do this.
    I tried the following:
    Code:
    String SelectItem_lastValue = Cookies.getCookie("SelectItem_lastValue");
    someForm.setDataSource(myDS);
    someForm.fetchData();
    RecordList recordList = someForm.getRecordList();
    Record previouslySelected = recordList.find("recordID", SelectItem_lastValue);
    but got a
    Code:
    com.google.gwt.core.client.JavaScriptException: (TypeError): self.find is not a function
    error.

    What is the recommended way to do this? Any other ideas?

    Thanks
    fatzopilot

    #2
    Yes you should call setValue and pass in the id of the record that you want to have displayed.

    But what I'm not seeing in your code is where you set the value field (aka "ID) and the display field. Ex:

    Code:
    _companyBox = new SelectItem();
    _companyBox.setShowTitle(false);
    _companyBox.setWidth(175);
    _companyBox.setValueField("id");
    _companyBox.setDisplayField("name");
    After having set up your SelectItem correctly all you would have to do is call the setValue method:

    _companyBox.setValue(lastID);

    Comment


      #3
      Hi chodges,

      the code was missing the

      Code:
      _companyBox.setValueField("id");
      _companyBox.setDisplayField("name")
      part, indeed. Now it works as expected, thank you!
      fatzopilot

      Comment

      Working...
      X