Announcement

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

    ComponentSchema and Smartgwt 3.1

    Hi,

    according to http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/ComponentSchema.html (identically found in the smartgwtpower3.1 distribution) it should be possible to define Component Schema to extend basic classes or at least, to pre define some attributes on them.
    I tried this
    NewCustomGrid.ds.xml
    Code:
    <DataSource ID="NewCustomGrid" serverType="component"
    	inheritsFrom="ListGrid" instanceConstructor="com.aCompany.client.ui.CustomListGrid"
    	autoDraw="false">
    </DataSource>
    Screen.ui.xml
    Code:
    <isomorphicXML xmlns:fmt="WEB-INF/">
    	<DataSource>
    	    <loadID>someBean</loadID>
    	</DataSource>
    	
    	<NewCustomGrid dataSource="ref:someBean" autoFetchData="true" ID="someBeanListGrid" autoDraw="false">
    	    <fields>
    	       ...
    	    </fields>
    	    <listEndEditAction>next</listEndEditAction>
    	    <showFilterEditor>true</showFilterEditor>
    	    <canEdit>true</canEdit>
    	    <canRemoveRecords>true</canRemoveRecords>
    	</NewCustomGrid>
    </isomorphicXML>
    CustomListGrid.java
    Code:
    package com.aCompany.client.ui;
    
    import com.google.gwt.core.client.JavaScriptObject;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
    import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
    
    public class CustomListGrid extends ListGrid {
    
    	public CustomListGrid() {
    		super();
    		System.out.println("It workds!");
    		addRecordClickHandler(new RecordClickHandler() {	
    			@Override
    			public void onRecordClick(RecordClickEvent event) {
    				SC.say("Record Pressed");
    			}
    		});
    	}
    
    	public CustomListGrid(DataSource dataSource) {
    		super(dataSource);
    		System.out.println("It workds!");
    		addRecordClickHandler(new RecordClickHandler() {	
    			@Override
    			public void onRecordClick(RecordClickEvent event) {
    				SC.say("Record Pressed");
    			}
    		});
    	}
    
    	public CustomListGrid(JavaScriptObject jsObj) {
    		super(jsObj);
    		System.out.println("It workds!");
    		addRecordClickHandler(new RecordClickHandler() {	
    			@Override
    			public void onRecordClick(RecordClickEvent event) {
    				SC.say("Record Pressed");
    			}
    		});
    	}
    
    	@Override
    	protected JavaScriptObject create() {
    		SC.say("It workds!");
    		return super.create();
    	}
    }
    and got the following error (in dev) when above Screen (using this component) was loaded:
    Code:
    12:35:26.719 [ERROR] [com.aCompany.GWTModule] 12:35:26.670:XRP1:WARN:Log:Error when executing loaded screen: TypeError: isc.com is undefined
    Stack from error.stack:
        unnamed() @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:306
        unnamed(isc_c_Class_evaluat) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:213
        unnamed(isc_c_Class_globalEvalWithCaptur) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:268
        unnamed(isc_c_RPCManager_loadScreen/_6.callbac) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1242
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:311
        unnamed(isc_c_RPCManager_fireReplyCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1221
        unnamed($wnd.isc.RPCManager.fireReplyCallbac) @ :234
        unnamed(isc_c_RPCManager_fireReplyCallback) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1224
        unnamed(isc_c_RPCManager_performOperationRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1221
        unnamed(isc_c_RPCManager__performTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1215
        unnamed(isc_c_RPCManager_performTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1181
        unnamed(anonymou) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:63
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_c_Comm_performXmlTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:930
        unnamed(anonymou) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:63
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_c_Comm__fireXMLCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:912
        unnamed(isc_c_Comm_sendXmlHttpRequest/_1) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:917
        unnamed() @ 
    com.smartgwt.client.core.JsObject$SGWT_WARN: 12:35:26.670:XRP1:WARN:Log:Error when executing loaded screen: TypeError: isc.com is undefined
    Stack from error.stack:
        unnamed() @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:306
        unnamed(isc_c_Class_evaluat) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:213
        unnamed(isc_c_Class_globalEvalWithCaptur) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:268
        unnamed(isc_c_RPCManager_loadScreen/_6.callbac) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1242
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:311
        unnamed(isc_c_RPCManager_fireReplyCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1221
        unnamed($wnd.isc.RPCManager.fireReplyCallbac) @ :234
        unnamed(isc_c_RPCManager_fireReplyCallback) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1224
        unnamed(isc_c_RPCManager_performOperationRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1221
        unnamed(isc_c_RPCManager__performTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1215
        unnamed(isc_c_RPCManager_performTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_DataBinding.js:1181
        unnamed(anonymou) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:63
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_c_Comm_performXmlTransactionRepl) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:930
        unnamed(anonymou) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:63
        unnamed(isc_c_Class_fireCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:256
        unnamed(isc_c_Comm__fireXMLCallbac) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:912
        unnamed(isc_c_Comm_sendXmlHttpRequest/_1) @ com.aCompany.GWTModule/sc/modules/ISC_Core.js:917
        unnamed() @ 
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
        at java.lang.Thread.run(Thread.java:722)
    Are the docs misleading here (in the sense that this is only possible when defining the component directly as JS class and not as GWT class (which for me is Java)) or did I omit something?

    Thanks,
    fatzopilot

    #2
    You can do this, but your class needs to be set up for reflection.

    Note that autoDraw="false" doesn't make sense on a Component Schema (does nothing).

    Comment


      #3
      Hi,

      The API for 3.1 is considerably different at this point, i.e. com.smartgwt.client.bean.BeanFactory does not exist. Is there still a way to register specific classes for reflection to use them in a component schema?

      Thanks,
      fatzopilot

      Comment


        #4
        No, this reflection capability is a 4.0 feature.

        Comment


          #5
          Apologies if I'm hijacking the thread here, but I'm curious to know what that DataSource element in Screen.ui.xml is supposed to do - and specifically the loadID element. I don't find any reference to that anywhere...

          Thanks in advance.
          Last edited by bbruyn; 31 May 2013, 09:39. Reason: clarification on the element in question

          Comment


            #6
            That will load the DataSource with the provided ID as part of loading the Component XML file. It's a facility used by Visual Builder to create a self-contained Component XML file for a page, and shouldn't really be directly used in a normal app.

            Comment


              #7
              That's what it looked like. I have a case where this might be useful in my app - can you explain what you mean by, "shouldn't really be directly used in a normal app"?

              I gave it a whirl in a little test case and though things end up working in the end, I am greeted with the following along the way

              Code:
              java.lang.ClassCastException: com.smartgwt.client.data.DataSource cannot be cast to com.smartgwt.client.core.DataClass
                  at com.smartgwt.client.util.ObjectFactory.createInstance(ObjectFactory.java)
                  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:172)
                  at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                  at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                  at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
                  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:242)
                  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:172)
                  at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                  at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                  at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
                  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:242)
                  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:172)
                  at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                  at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                  at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
                  at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
                  at com.smartgwt.client.util.JSOHelper.convertToJava(JSOHelper.java)
                  at com.smartgwt.client.util.JSOHelper.convertToMap(JSOHelper.java:647)
                  at com.smartgwt.client.util.JSOHelper.convertToMap(JSOHelper.java:665)
                  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:172)
                  at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                  at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                  at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                  at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
                  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:242)
                  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:172)
                  at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
                  at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
                  at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
                  at java.lang.Thread.run(Thread.java:662)

              Comment


                #8
                Basically using the <DataSource> tag in this way is an unconditional load of the DataSource. So loading the same DataSource twice this way would result in clobbering the DataSource definition, with undefined behavior after that. So it's generally better to go through DataSource.load().

                Comment

                Working...
                X