Announcement

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

    ClassCastException in getEditFormItem after SmartGWT upgrade to 12.1

    Hi Team,

    I have addEditorEnterHandler specified for a ListGrid, which has some field editors specified as ComboBoxItem

    In SmartGWT 4.1, we were having below code,

    Code:
    @Override
    public void onEditorEnter(EditorEnterEvent event) {
            ListGrid editedGrid = event.getGrid();
            if(editedGrid!=null){
            FormItem fieldEditor=editedGrid.getEditFormItem(FIELD_NAME);
            if (null != fieldEditor) {
                  ComboBoxItem combo = (ComboBoxItem) fieldEditor;
    After upgrading to SmartGWT 12.1, I am getting below exception,

    Code:
    Caused by: java.lang.ClassCastException: com.smartgwt.client.widgets.form.fields.TextItem cannot be cast to com.smartgwt.client.widgets.form.fields.ComboBoxItem
    Can you suggest how to achieve what i want here ?

    #2
    This looks like the editor simply isn't a ComboBoxItem? Is it? What does your attempt to configure it as a comboBox look like?

    Comment


      #3
      Hi Team,

      I have verified that I am having below code which configures it as a ComboBoxItem

      Code:
      public static ComboBoxItem configureComboBoxOptionDataSource(ListGridField listGridField, final JsonDataDs dataDs, final String fieldName) {
              ComboBoxItem editorType = new ComboBoxItem();
              editorType.setDisplayField(dataDs.getDisplayField());
              editorType.setValueField(dataDs.getValueField());
              editorType.setOptionDataSource(dataDs);
              editorType.setSortField(dataDs.getDisplayField());
              editorType.setAlwaysFetchMissingValues(true);
              editorType.setAddUnknownValues(false);
              editorType.setRejectInvalidValueOnChange(true);
              editorType.setTextMatchStyle(TextMatchStyle.SUBSTRING);
              listGridField.setEditorProperties(editorType);
              listGridField.setDisplayField(dataDs.getDisplayField());
              listGridField.setValueField(dataDs.getValueField());
              return editorType;
          }
      Please note that, I have also tried below property but the result was same,

      Code:
      listGridField.setEditorType(editorType.getClass());

      Comment


        #4
        That setEditorType() call is definitely required.

        Do not use getClass() in GWT, GWT doesn’t really support Java reflection APIs. Just pass ComboBoxItem directly.

        If that doesn’t work, at this point you are showing usage that is a close match to several Showcase examples, so we will need a minimal, ready-to-run test case to look again.

        Comment


          #5
          Hi Isomorphic,

          Do you mean i should use setEditorType(FormItem editorType) or setEditorType(String editorType) since former one is same as setEditorProperties(FormItem editorProperties)

          Comment


            #6
            Please read the docs: use the String one. The Class one can only be used if you use the Reflection set up - it's for custom classes.

            The third signature (passing a FormItem instance) is deprecated, so obviously don't use that.

            Comment


              #7
              But the string one has below javadoc comment for parameter passed,

              the fully-qualified class name of a {@link com.smartgwt.client.widgets.form.fields.FormItem}
              * subclass, which must have been registered with the
              * {@link com.smartgwt.client.docs.Reflection reflection mechanism}.

              Comment


                #8
                Yes, there is a link in the next sentence where you can read up on the possible limitations, which do not apply here.

                Anyway, let us know if you find any evidence that there is a framework bug here, by providing a minimal, ready-to-run test case.

                Comment


                  #9
                  Just one update, that in the edited cell it shows the combobox correctly. Any reason why it would give TextItem in getEditFormItem ?

                  Comment


                    #10
                    There is no reason, or we would have told you. That's why we need a test case - to see how you are getting that to happen.

                    Comment


                      #11
                      Hi Isomorphic,

                      I tried to replicate using test case, but it is working fine there.

                      Do you know if I purchase support license than it would help me without needing to submit test case ?

                      Comment


                        #12
                        Right now all we have is some short snippets of code that don’t show a problem. We have no way to reproduce the problem. There is no way for anyone to help you right now, no matter what support plan was purchased.

                        We do offer consulting services, and consultants could just take a look at your entire project rather than asking for a test case. Support doesn’t look at problem unless you can show us there’s a framework bug.

                        Comment


                          #13
                          I am unable to replicate it in a test case, but found one more information on issue i am facing,


                          Code:
                           ListGrid editedGrid = event.getGrid();
                                                          if(editedGrid!=null){
                                                              FormItem fieldEditor=editedGrid.getEditFormItem(UiFieldConstants.FIELD_PRDDEF_ASSET_TYPE_ID);
                                                              SC.logWarn(fieldEditor.getClassName());
                                                              if (null != fieldEditor) {
                                                                  ComboBoxItem combo = (ComboBoxItem) fieldEditor;
                          In SC.logWarn, it is showing class name as ComboBoxItem, still it is giving ClassCastException while casting it to ComboBoxItem

                          This anomaly can also be seen in attached screenshot, please notice difference between fitlerEditor object seen in scope are of Chrome debugger Click image for larger version

Name:	SS4.png
Views:	165
Size:	299.5 KB
ID:	262779

                          Comment


                            #14
                            Definitely nonsense, and if you are still not getting normal stack traces, this problem may be connected - something basic is wrong with your GWT environment. We have previously recommended that you rebuild your environment from scratch, and we still recommend that.

                            Comment

                            Working...
                            X