Announcement

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

    ValuesManager and fetchData leads to ClassCastException

    I'm working on a dialog (extending BaseDialog) with a TabSet form layout split into several tabs, basically as described in <a href="http://www.smartclient.com/smartgwt/showcase/#layout_form_splitting">the gwt showcase</a>.

    The GUI itself works fine, I also can use a ValuesManager and provide data via ValuesManager.setValues(...).
    What does not work is - instead of using setValues(...) - connecting the form to a datasource via a ValuesManager as described in
    <a href="http://www.smartclient.com/docs/6.5.1/a/b/c/go.html#class..ValuesManager">the smartclient docs</a>.

    I tried to connect the skeleton from the documentation to a datasource like this:
    Code:
    ValuesManager vm = new ValuesManager();
    vm.setDataSource(dataSource);
    myFormOne.setDataSource(dataSource);
    myFormTwo.setDataSource(dataSource);
    vm.addMember(myFormOne);
    vm.addMember(myFormTwo);
    All this works, but when I call
    Code:
    vm.fetchData()
    to write the data from the datasource to the form fields, I get a ClassCastException (which is added to the end of this message).
    I was able to debug it to the method invocation, and it seems that within my call to ValuesManager.fetchData(...), the method
    Code:
    public com.google.gwt.core.client.JavaScriptObject com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj()
    is executed on my instance of ValuesManager in
    Code:
    com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
    ValuesManager is not of type BaseWidget but only extends class com.smartgwt.client.core.BaseClass.

    Any ideas about this? Is the setup of the values manager wrong for this case?

    kind regards



    This is the part of the stack trace.
    Code:
    description: java.lang.IllegalArgumentException: java.lang.ClassCastException@8c0a3b
    	at sun.reflect.GeneratedMethodAccessor8.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.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
    	at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
    	at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
    	at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
    	at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
    	at org.eclipse.swt.internal.ole.win32.COM.VtblCall(Native Method)
    	at org.eclipse.swt.internal.ole.win32.IDispatch.Invoke(IDispatch.java:64)
    	at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:493)
    	at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:417)
    	at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.doInvokeOnWindow(ModuleSpaceIE6.java:67)
    	at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.doInvoke(ModuleSpaceIE6.java:152)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:447)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:248)
    	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    	at com.smartgwt.client.widgets.form.ValuesManager.fetchData(ValuesManager.java)
    	at com.ect.effective.gwt.vcb.client.dlg.PromptDialog.<init>(PromptDialog.java:77)
    	at com.ect.effective.gwt.vcb.client.dlg.DialogFactory.createDialog(DialogFactory.java:28)

    #2
    Fixed in SVN.

    Sanjiv

    Comment


      #3
      Fix works, but how is validation propagated?

      I'm impressed by the promptness of the solution. Thanks, the change works.

      I now run into another problem which also has to do with the ValuesManager:

      Lets take my example from before, so I have again the ValuesManager, TabSet and two forms myFormOne, myFormTwo.
      I now add two databound fields to the datasource as in
      Code:
      DataSourceTextField dsName = new DataSourceTextField("name", "Name", 20, true);
      DataSourceTextField dsPreName = new DataSourceTextField("prename", "Prename", 20, true);
      dataSource.setFields(new DataSourceField[] {dsName, dsPreName});
      What I need to do is to show the mandatory 'name' in the first tab, and the mandatory 'prename' in the second tab. This works well by hiding the fields like in
      Code:
      myFormOne.hideItem("prename");
      myFormTwo.hideItem("name");
      I did not find another way to do this.
      When I now have entered valid data for the field 'name' on the first tab, and also data for field 'prename' on the second tab and I validate the data via the ValuesManager as in
      Code:
      valuesManager.validate();
      it returns false and I get an error message "Invalid value" from
      Code:
      valuesManager.getUnknownErrorMessage()
      I can see in the SmartClient Developer Console that the ValuesManager validates all elements of all its forms, no matter if they are visible or not:
      Code:
      12:04:13.297:MUP9:DEBUG:DynamicForm:myFormOne:Applying 1 validators to field 'name' with value 'Prompt'
      12:04:13.297:MUP9:DEBUG:DynamicForm:myFormOne:Applying 1 validators to field 'prename' with value 'null'
      12:04:13.313:MUP9:INFO:DynamicForm:myFormOne:Validation errors: {prename: "Field is required"}
      12:04:13.313:MUP9:DEBUG:DynamicForm:myFormTwo:Applying 1 validators to field 'name' with value 'undefined'
      12:04:13.313:MUP9:DEBUG:DynamicForm:myFormTwo:Applying 1 validators to field 'prename' with value 'prename'
      12:04:13.313:MUP9:INFO:DynamicForm:myFormTwo:Validation errors: {name: "Field is required"}
      12:04:13.329:MUP9:WARN:validation:isc_OID_29:Validation failed with the following errors:
      prename:- Field is required
       - Field is required
      name:- Field is required
      So even though I have entered valid data into both mandatory fields I still get an error because the ValuesManager valdates all data on both forms. Is there any way to workaround checks on invisible form fields? Or should the assignment of databound elements to multiple forms be done in a different way? The DynamicForm has a validate(boolean validateHiddenFields), but that is not the ValuesManager and I guess this would only work for form fields, not for databound fields.
      Any ideas?
      Last edited by ect; 19 Jan 2009, 03:06.

      Comment


        #4
        You can specify fields on the individual forms to make those forms show a subset of the DataSource fields. ValuesManager.validate() will then validate the overall compound form and show the errors in the form fields that are showing those fields.

        BTW, I think you're Developer Console probably has warnings telling you there are colliding fields in multiple forms.

        Comment

        Working...
        X