Announcement

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

    ClassCastException when using RichTextItem as editor type

    I'm having a problem using RichTextItem as an editor type on FormItems. I am calling setEditorType() on a FormItem and adding that FormItem to a DynamicForm. When I call editNewRecord() on the form, I am getting a ClassCastException.

    This section here will cause it to happen:
    Code:
        FormItem formItem = new FormItem();
        formItem.setEditorType(new RichTextItem());
        DynamicForm form = new DynamicForm();
        form.setFields(formItem);
        form.editNewRecord();
    The exception does not occur if I specifically create a RichTextItem instead of using setEditorType(). Is RichTextItem supposed to work as an editor type or do I need to do something differently?

    Thanks,
    Reed


    java.lang.ClassCastException: null
    at java.lang.Class.cast(Class.java:2990)
    at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:163)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:57)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    at com.smartgwt.client.widgets.BaseWidget.setProperty(BaseWidget.java)
    at com.smartgwt.client.widgets.BaseWidget.setAttribute(BaseWidget.java:628)
    at com.smartgwt.client.widgets.form.DynamicForm.setFields(DynamicForm.java:2732)
    at com.kohls.packet1forms.client.RichTextItemTest.<init>(RichTextItemTest.java:15)
    at com.kohls.packet1forms.client.AppFactory.createApp(AppFactory.java:114)
    at com.kohls.packet1forms.client.App$1.onRecordClick(App.java:72)
    at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:98)
    at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:1)
    at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:237)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:619)

    #2
    Yes, it works as an editorType, but why would you create a FormItem and set it as the editorType, when you can just pass it to setFields() directly?

    Comment


      #3
      The software we're writing involves creating a large number of forms. For each form, we're writing a Datasource, using custom annotations to drive the behavior of the form items that will appear on the DynamicForm. We are not creating each individual FormItem manually, the goal is to write little or no custom Smart GWT code for each form. We create a basic DynamicForm and bind it to the corresponding annotated Datasource to determine what types of fields will appear.

      Here's an example of what might appear in a DataSource file:
      Code:
      @RichText(some optional attributes)
      public String someRichText;
      When we process this DataSource file to create a DynamicForm, the annotation says this field needs to be a rich text field. We create a RichTextItem based on the annotation, and then set it as the editor type for the DataSourceField that was annotated. We aren't writing a specific RichTextItem for each field that requires it, so we can't directly pass them to setFields(). This same principle applies for all types of fields: read annotations (if any), create the necessary FormItem, and set it as the editor type for the DataSourceField.

      Hope this makes sense, any help on the editNewRecord() exception would be great. Thanks.

      Comment


        #4
        That's all typical usage, but doesn't require that you specifically create a FormItem and setEditorType() on it, which is a strange way of doing things, instead you're expected to setEditorType() on a DataSource field.

        Let us know if you encounter a problem doing things the normal way, and if so, show a test case that can reproduce the problem, as well as including all the version information you should always be posting.

        Comment


          #5
          I attached a test case that reproduces this exception. I am setting the editor type on a DataSource as opposed to a FormItem. Setting the editor type of DataSource fields generally works for me. However, it seems that trying when to use an editor type of RichTextItem or some other FormItems which extend CanvasItem, I get the ClassCastException.

          I could provide a longer example if needed, using the same method with other editor types that seem to work fine, but I kept it as short as possible to just show the RichTextItem editor type.

          I am using GWT SDK 2.3.0, the 6-30 nightly Smart GWT, and am using recent versions of Firefox and Chrome, running in Development Mode. Windows 7 Professional.

          Thanks for any help on this.
          Attached Files

          Comment


            #6
            Thanks for the test case. We have made a change which should resolve this issue (will be present in the upcoming 2.5 release)

            Comment


              #7
              Thanks very much, I'll let you know if I run into any issues once I'm using 2.5 with the fix.

              Comment

              Working...
              X