Announcement

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

    ComboBoxItem is not displaying selected value

    gwt-maven-plugin.version - 2.8.1
    gwt.version - 2.8.1
    ​​​​smart-gwt.version - 12.1-p20201029
    browser - Version 86.0.4240.183 (Official Build) (x86_64)
    os - mac

    Code:
    protected FormItem createVulnNameFormItem() {
      final ComboBoxItem item = new ComboBoxItem();
      item.setRequired(true);
      item.setWidth("400");
      item.setName("Name");
      item.setTitle("Name");
      item.setValueField("id");
      item.setDisplayField("name");
      item.setShowPickerIcon(true);
      item.setShowHint(true);
      item.setShowHintInField(true);
      item.setHint("Enter Name");
      item.addClickHandler(createNameItemClickHandler(item));
    
      return item;
    }
    
    protected ClickHandler createNameItemClickHandler(final ComboBoxItem item) {    
      return new ClickHandler() {        
        @Override      
        public void onClick(ClickEvent event) {          
          onClick = true;          
          boolean validate = validateRecord();          
          if (validate == true) {            
            NameRestDS nameRestDS = NameRestDS.getInstance();            
            String filterByValue = (String) filterByFormItem.getValue();            
            final Criteria criteria = new Criteria();            
            criteria.setAttribute("type");            
            criteria.setAttribute("filterBy", filterByValue);            
            item.setOptionCriteria(criteria);
            item.setOptionDataSource(nameRestDS);
            item.setFetchDelay(50);
            item.setAutoFetchData(true);
            item.setFilterLocally(false);
            item.setCachePickListResults(false);          
          }      
        }    
      };
    }
    
    
    //Response from API
    
    {
      response: {
        status: 0,
        startRow: 0,
        endRow: 1,
        totalRows: 1,
        data: [
          {
            id: 1,
            name: "Name"
          }
        ]
    
      }
    }
    
    //NameRestDS
    public static NameRestDS getInstance() {
    setID("NameRestDS");
    setJsonPrefix("");
    setJsonSuffix("");
    setDataFormat(DSDataFormat.JSON);
    OperationBinding fetch = new OperationBinding();
    fetch.setOperationType(DSOperationType.FETCH);
    fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Accept", "application/json");
    DSRequest request = new DSRequest();
    request.setHttpHeaders(headers);
    fetch.setRequestProperties(request);
    setOperationBindings(fetch);
    setFetchDataURL("rest/getlist/");
    DataSourceIntegerField idDS = new DataSourceIntegerField("id", "ID");
    DataSourceTextField nicknameDS = new DataSourceTextField("name", "Name");
    nicknameDS.setEscapeHTML(true);
    setFields(idDS, nicknameDS);
    }
    ComboBoxItem displays the list returned from the API.
    Selected an item in the dropdown but it's not displayed/selected in the combo input box.
    Am I missing any parameters to be set?
    Last edited by jayasree; 6 Nov 2020, 04:40.

    #2
    You're making a weird attempt to set properties on the ComboBox via a clickHandler. It's difficult to see why you would do this, but in any case, it won't work, and your code is either crashing or there are loud warnings telling you this is not allowed - look at your console.

    Comment


      #3
      The weird code worked with Smartgwt 3 in the legacy application. On upgrading to 12.1, I see this issue.

      The code below doesn't even display the list from the API.

      Code:
      protected FormItem createVulnNameFormItem() {
        final ComboBoxItem item = new ComboBoxItem();
        item.setRequired(true);
        item.setWidth("400");
        item.setName("Name");
        item.setTitle("Name");
        item.setValueField("id");
        item.setDisplayField("name");
        item.setShowPickerIcon(true);
        item.setShowHint(true);
        item.setShowHintInField(true);
        item.setHint("Enter Name");    
        NameRestDS nameRestDS = NameRestDS.getInstance();
        String filterByValue = (String) filterByFormItem.getValue();
        final Criteria criteria = new Criteria();
        criteria.setAttribute("type");
        criteria.setAttribute("filterBy", filterByValue);
        item.setOptionCriteria(criteria);
        item.setOptionDataSource(nameRestDS);
        item.setFetchDelay(50);
        item.setAutoFetchData(true);
        item.setFilterLocally(false);
        item.setCachePickListResults(false);
        return item;
      }
      Attached console log.

      Click image for larger version

Name:	Screenshot 2020-11-08 at 2.24.41 AM.png
Views:	72
Size:	217.9 KB
ID:	264021
      Attached Files

      Comment


        #4
        Yes, one of the typical ways to have something break on upgrade is to rely on something that doesn’t match the docs.

        The console log indicates that your obfuscated application code has crashed (framework code from us would not have obfuscated names).

        Please let us know if you find any evidence of a problem with the framework.

        Comment

        Working...
        X