Announcement

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

    nullpointer on datasource for sample db application

    Inspite of all the trials and error, I could not run the sample application. Any help in this will be of great help to a newbie like me.

    In order to use smartGWTEE feature, I created a db interaction and CRUD sample as per the guidelines given in EE showcase.

    I created a standard project gwt web application.
    Copied all files from WEB-INF/lib directory of the smartGWTEE > showcase demo > lib to myproject WEB-INF/lib.
    Copied the server.properties from the showcase to myproject and changed relavant things.

    ### Here is my code ###

    src > crud > client > ds > countries.ds.xml :
    Code:
    <!-- Auto-generated from database table countries -->
    
    <DataSource 
    	dbName="zoe"
    	tableName="countries"
    	ID="countries"
    	dataSourceVersion="1"
    	generatedBy="7.1a/Enterprise Development Only 2009-06-24"
    	serverType="sql"
    >
    	<fields>
    		<field primaryKey="true" name="countriesid" type="sequence"></field>
    		<field name="insertby" length="50" type="text"></field>
    		<field name="updateby" length="50" type="text"></field>
    		<field name="inserttime" type="date"></field>
    		<field name="updatetime" type="date"></field>
    		<field name="countrycode" length="3" type="text"></field>
    		<field name="countryname" length="100" type="text"></field>
    	</fields>
    </DataSource>
    Code:
    package gtl.crud.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
    import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VStack;
    import com.smartgwt.client.widgets.viewer.DetailViewer;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Gtlcrud implements EntryPoint {
    	
    	public void onModuleLoad() {
    		DataSource dataSource = DataSource.get("countries");
    		
            VStack vStack = new VStack();
            vStack.setLeft(175);
            vStack.setTop(75);
            vStack.setWidth("70%");
            vStack.setMembersMargin(20);
    
            Label label = new Label();
            label.setContents("<ul>" +
                    "<li>click a record in the grid to view and edit that record in the form</li>" +
                    "<li>click <b>Save</b> to save changes to an edited record in the form</li>" +
                    "<li>click <b>Clear</b> to clear all fields in the form</li>" +
                    "<li>enter text like \"board\" in the Item field and click <b>Filter</b> to filter (substring match) the grid based on the value Item form value only.</li>" +
                    "<li>select a row and click <b>Fetch</b> to fetch records (exact match) for the grid based on the value of the 'Item' form value only.</li>" +
                    "<li>click <b>Delete</b> to delete all selected records</li>" +
                    "<li>double-click a record in the grid to edit inline (press Return, or arrow/tab to another record, to save)</li>" +
                    "</ul>");
            vStack.addMember(label);
    
            // databound ListGrid
            //   * click records to edit in boundForm and view in boundViewer
            //   * double-click record to edit inline (Return or arrow/tab off current row to save)
            final ListGrid boundList = new ListGrid();
    
            boundList.setDataSource(dataSource);
            boundList.setHeight(200);
            boundList.setCanEdit(true);
            vStack.addMember(boundList);
    
            final DynamicForm boundForm = new DynamicForm();
            boundForm.setDataSource(dataSource);
            boundForm.setNumCols(4);
            boundForm.setAutoFocus(false);
            vStack.addMember(boundForm);
    
            HLayout toolbar = new HLayout();
            toolbar.setMembersMargin(10);
            toolbar.setHeight(22);
    
            final IButton saveBtn = new IButton("Save");
            saveBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    boundForm.saveData();
                    if (!boundForm.hasErrors()) {
                        boundForm.clearValues();
                        saveBtn.disable();
                    }
                }
            });
            toolbar.addMember(saveBtn);
    
            final IButton newBtn = new IButton("New");
            newBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    boundForm.editNewRecord();
                    saveBtn.enable();
                }
            });
            toolbar.addMember(newBtn);
    
            IButton clearBtn = new IButton("Clear");
            clearBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    boundForm.clearValues();
                    saveBtn.disable();
                }
            });
            toolbar.addMember(clearBtn);
    
            IButton filterBtn = new IButton("Filter");
            filterBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    boundList.filterData(boundForm.getValuesAsCriteria());
                    saveBtn.disable();
                }
            });
            toolbar.addMember(filterBtn);
    
            IButton fetchBtn = new IButton("Fetch");
            fetchBtn.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    boundList.fetchData(boundForm.getValuesAsCriteria());
                    saveBtn.disable();
                }
            });
            toolbar.addMember(fetchBtn);
    
            vStack.addMember(toolbar);
    
            final DetailViewer boundViewer = new DetailViewer();
            boundViewer.setDataSource(dataSource);
            vStack.addMember(boundViewer);
    
            boundList.addRecordClickHandler(new RecordClickHandler() {
                public void onRecordClick(RecordClickEvent event) {
                    Record record = event.getRecord();
                    boundForm.editRecord(record);
                    saveBtn.enable();
                    boundViewer.viewSelectedData(boundList);
                }
            });
    
            boundList.filterData(new Criteria());
    
            vStack.draw();
    
    	}
    }
    src > crud > Gtlcrud.gwt.xml :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
    <module rename-to='gtlcrud'>
      <!-- Inherit the core Web Toolkit stuff.                        -->
      <inherits name='com.google.gwt.user.User'/>
    
      <!-- Inherit the default GWT style sheet.  You can change       -->
      <!-- the theme of your GWT application by uncommenting          -->
      <!-- any one of the following lines.                            -->
      <inherits name='com.google.gwt.user.theme.standard.Standard'/>
      <inherits name="com.smartgwt.SmartGwt"/>
      <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
      <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->
    
      <!-- Other module inherits                                      -->
    
      <!-- Specify the app entry point class.                         -->
      <entry-point class='gtl.crud.client.Gtlcrud'/>
    </module>

    src > server.properties :

    Code:
      
    webRoot: __AUTODETECT__   
      
    isomorphicPathRootRelative: gtlcrud/sc  
       
    apps.adminConsole.location: $webRoot/gtlcrud/tools   
    ui.adminConsole.location: $webRoot/gtlcrud/tools   
      
    sql.defaultDatabase: Mysql
    
    # -------------- SETTINGS FOR MYSQL --------------------   
      
    # These are the settings for use with the Mysql database.  If you have   
    # just done a fresh install of MySQL on the same machine where you are   
    # running your servlet engine, the values provided below will probably   
    # just work on most platforms.   
      
    # Configuration for Mysql Connector/J   
    sql.Mysql.database.type: mysql   
    sql.Mysql.database.ansiMode: false   
    sql.Mysql.interface.type: dataSource   
    #sql.Mysql.driver: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    sql.Mysql.driver: com.mysql.jdbc.Driver   
    # name of the database to use   
    sql.Mysql.driver.databaseName: ns
    # hostname and port where the database server is installed   
    sql.Mysql.driver.serverName: localhost   
    sql.Mysql.driver.portNumber: 3306   
    # username and password that can create and modify tables in that database   
    # this user must have the following privileges for the system to function   
    # properly: create/alter/drop table; insert/update/replace/delete rows.   
    sql.Mysql.driver.user: root   
    sql.Mysql.driver.password:root   
      
      
    # -------------- LOADING APP AND DATASOURCE DEFINITIONS --------------------   
      
    # Where the system looks for DataSource definition files ([dataSourceId].ds.xml or   
    # [dataSourceID].ds.js).  It's useful to put all your DataSources in one   
    # directory since DataSources are frequently shared between applications.   
    # "project.datasources" is also where the DataSource Importer tool looks   
    # for available DataSources.   
    project.datasources:gtl/crud/client/ds   
    project.ui: $webRoot/shared/ui   
    project.apps: $webRoot/shared/app   
     
    RPCManager.enabledBuiltinMethods: *
    please refer to next part for some more details, this post has exceeded 10000 chars :)
    Last edited by nsanghavi; 20 Aug 2009, 20:24.

    #2
    Continued post: rest of the details

    Gtlcrud.html :

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link type="text/css" rel="stylesheet" href="Gtlcrud.css">
    
    <title>Web Application Starter Project</title>
    
    <script>
    		var isomorphicDir = "gtlcrud/sc/";
    </script>
    
    <script type="text/javascript" language="javascript"
    	src="gtlcrud/gtlcrud.nocache.js"></script>
    </head>
    
    <script src="sc/DataSourceLoader?dataSource=countries"></script>
    
    <body>
    </body>
    </html>
    web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
      
      <!-- Servlets -->
      <servlet>
            <servlet-name>DataSourceLoader</servlet-name>
            <servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>DataSourceLoader</servlet-name>
            <url-pattern>/sc/DataSourceLoader</url-pattern>
        </servlet-mapping>
        
        
        
    
        <!-- The IDACall servlet handles all Built-in DataSource operations -->
        <servlet>
            <servlet-name>IDACall</servlet-name>
            <servlet-class>com.isomorphic.servlet.IDACall</servlet-class>
        </servlet>
    
        <!-- The DataSourceLoader servlet returns Javascript representations of the dataSources whose
             ID's are passed to it - it is an alternative to using the <loadDS> JSP tag -->
     
    
        <!-- The FileDownload servlet downloads static files, like a webserver -->
        <servlet>
            <servlet-name>FileDownload</servlet-name>
            <servlet-class>com.isomorphic.servlet.FileDownload</servlet-class>
        </servlet>
    
        <!-- //>RealtimeMessaging -->
        <!-- The MessagingServlet is used by realtime messaging -->
        <servlet>
            <servlet-name>MessagingServlet</servlet-name>
            <servlet-class>com.isomorphic.messaging.MessagingServlet</servlet-class>
        </servlet>
        <!-- //<RealtimeMessaging -->
    
    
        <!-- ISC init: initializes ISC framework -->
        <servlet>
            <servlet-name>Init</servlet-name>
            <servlet-class>com.isomorphic.base.Init</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet>
            <servlet-name>HttpProxy</servlet-name>
            <servlet-class>com.isomorphic.servlet.HttpProxyServlet</servlet-class>
        </servlet>
    
        <!-- The PreCache servlet initializes when the servlet engine starts up and pre-loads 
             data need for all client requests.  This is optional, and improves performance
             of the first few page requests.  PreCache cannot be invoked by a browser, because
             there is no "servlet-mapping" defined for it. -->
        <servlet>
            <servlet-name>PreCache</servlet-name>
            <servlet-class>com.isomorphic.servlet.PreCache</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
    
    
       
        <!-- RPCManager uses this URL by default for Built-in DataSource operations -->
        <servlet-mapping>
            <servlet-name>IDACall</servlet-name>
            <url-pattern>/gtlcrud/sc/IDACall/*</url-pattern>
        </servlet-mapping>
    
        <!-- DataSourceLoader requests -->
    
    
        <servlet-mapping>
            <servlet-name>HttpProxy</servlet-name>
            <url-pattern>/gtlcrud/sc/HttpProxy/*</url-pattern>
        </servlet-mapping>
    
        <!-- //>RealtimeMessaging -->
        <!-- Messaging uses this URL by default -->
        <servlet-mapping>
            <servlet-name>MessagingServlet</servlet-name>
            <url-pattern>/gtlcrud/sc/messaging/*</url-pattern>
        </servlet-mapping>
        <!-- //<RealtimeMessaging -->
    
        <!-- Use FileDownload servlet to download all static content that's part of the skin, such as
             image files, so we can set Expires headers and other cache control directives.  In a
             production deployment, you'd want to use a webserver such as Apache to do this.  
        -->
        <servlet-mapping>
            <servlet-name>FileDownload</servlet-name>
            <url-pattern>/gtlcrud/sc/skins/*</url-pattern>
        </servlet-mapping>
    
        <!-- serve ISC modules compressed, with expires headers -->
        <servlet-mapping>
            <servlet-name>FileDownload</servlet-name>
            <url-pattern>/gtlcrud/sc/system/modules/*</url-pattern>
        </servlet-mapping>
    
        <!-- serve ISC development modules compressed, with expires headers -->
        <servlet-mapping>
            <servlet-name>FileDownload</servlet-name>
            <url-pattern>/gtlcrud/sc/system/development/*</url-pattern>
        </servlet-mapping>
    
        <!-- server skin assets with expires headers -->
        <servlet-mapping>
            <servlet-name>FileDownload</servlet-name>
            <url-pattern>/gtlcrud/sc/system/reference/skin/*</url-pattern>
        </servlet-mapping>
      
      <!-- Default page to serve -->
      <welcome-file-list>
        <welcome-file>Gtlcrud.html</welcome-file>
      </welcome-file-list>
    
    </web-app>

    Console error:
    Code:
    [ERROR] Unable to load module entry point class gtl.crud.client.Gtlcrud (see associated exception for details)
    java.lang.NullPointerException: null
    	at com.smartgwt.client.widgets.grid.ListGrid.setDataSource(ListGrid.java:6877)
    	at gtl.crud.client.Gtlcrud.onModuleLoad(Gtlcrud.java:50)
    	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.ModuleSpace.onLoad(ModuleSpace.java:326)
    	at com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace(BrowserWidget.java:343)
    	at com.google.gwt.dev.shell.ie.BrowserWidgetIE6.access$300(BrowserWidgetIE6.java:37)
    	at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.gwtOnLoad(BrowserWidgetIE6.java:77)
    	at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.invoke(BrowserWidgetIE6.java:161)
    	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.win32.OS.DispatchMessageW(Native Method)
    	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
    	at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
    	at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
    	at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
    	at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

    Comment


      #3
      Your DataSource is not loading.

      1. check the server-side log for errors relating to trying to load the DataSource. For one, not sure if that comment is valid, being outside of the DataSource tag

      2. check the response of the DataSourceLoader servlet via Firebug - it may show an error as well, or be malformed in some obvious way.

      And actually, looking at your setting of project.dataSources in server.properties, is the file actually there? You realize that since that path doesn't start with webroot, it's relative to whatever directly your application server was started in? Did you intend that?

      Comment


        #4
        Hello ,I got the same problem

        In my GWT mudule's HTML file
        note:"ibmtest01" is my GWT module's name

        this is Error
        <script src="sc/DataSourceLoader?dataSource=db2admin"></script>

        and this is Correct
        <script src="ibmtest01/sc/DataSourceLoader?dataSource=db2admin"></script>

        I forgot type my GWT module name, so [ERROR] Unable to load module entry point .

        Sorry my English is very bad

        Comment


          #5
          Your datasource need to be gtl/crud/client/ds directory.

          Comment

          Working...
          X