Announcement

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

    GWT-RPC DataSource implementation

    Hi Sunnyl,

    Thanks so much for your response. May I ask the versions of
    - JDK
    - GWT
    -SmartGWT

    you are using in the example you created? :-)

    Btw, is this the way to go if I want to populate a ListGrid with data coming from an Oracle database? I am currently evaluating how to implement this using SmartGWT 2.0 with GWT 2.0 only without the usage of SmartGWT EE. Thanks so much!

    Regards.
    Last edited by junieboy; 25 Dec 2009, 19:25.

    Comment


      Hi junieboy,

      Seeing GWT 2.0 and SmartGWT 2.0 were just released recently I've checked that it works with these new versions. Download it again with the same link (http://www.group1solutions.com.au/sunny/smartgwt/datasource-test.zip)

      The project was created in Eclipse 3.5, JDK 1.6(u17?), now GWT 2.0 and SmartGWT 2.0. You'll need to drop the 2.0 JARs into the WEB-INF/lib directory after you've imported the project into Eclipse. I think Eclipse will automatically put the gwt-servlet JAR into WEB-INF/lib if your project references GWT 2.0.

      I think it is the way to go if you want to keep using GWT-RPCs (especially if you're comfortable with them, that, and SmartGWT EE isn't being used). Essentially the system flow becomes:

      GUI<->DataSource<->GWT-RPC<->GWT Service Implementations<->DB

      I've started a project taking this approach using a number of databound components (ListGrid and combos mostly) and its worked out well so far.

      Comparing this to my previous project where I used Stores in GWT-Ext, I think one complexity has been traded for another, although the SmartGWT approach to things is much cleaner, and having to use GwtRpcDataSource does force you to have a cleaner implementation IMO.

      regards
      Sunny


      Originally posted by junieboy
      Hi Sunnyl,

      Thanks so much for your response. May I ask the versions of
      - JDK
      - GWT
      -SmartGWT

      you are using in the example you created? :-)

      Btw, is this the way to go if I want to populate a ListGrid with data coming from an Oracle database? I am currently evaluating how to implement this using SmartGWT 2.0 with GWT 2.0 only without the usage of SmartGWT EE. Thanks so much!

      Regards.

      Comment


        Hi sunnyl,

        Just used your GwtRpcDataSource interface and it worked perfectly. Thank you for posting this example a while ago.

        Cheers,
        - Luc

        Comment


          JavaScriptException: (null) in DataSource.processResponse after switching to GWT2.0

          Hi,

          My simple datasource test (based on alius code) stopped working after switching to GWT2.0, both for smartgwt 1.3 and 2.0.
          My client view contains a ListGrid and a DynamicForm, both bound to the same datasource.
          After adding a record via the form, SimpleGwtRPCDS.executeAdd() gets executed and the call back onSuccess() throws when calling
          processResponse(requestId, response);
          This is not happening if the ListGrid is removed or not connected to the datasource.

          Thanks,
          Dmitriy

          09:29:18.133 [ERROR] [ds0604] Uncaught exception escaped
          com.google.gwt.core.client.JavaScriptException: (null): null
          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195)
          at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
          at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
          at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
          at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
          at com.smartgwt.client.data.DataSource.processResponse(DataSource.java)
          at my.client.SimpleGwtRPCDS$2.onSuccess(SimpleGwtRPCDS.java:122)
          at my.client.SimpleGwtRPCDS$2.onSuccess(SimpleGwtRPCDS.java:1)
          at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:216)
          Attached Files

          Comment


            Could you post the complete project? (the code seems to differ in places to the original example). I had this error as well, but after a large code overhaul it went away and I was completely unsure why. I'm also on 2.0.


            Originally posted by dimavin
            Hi,

            My simple datasource test (based on alius code) stopped working after switching to GWT2.0, both for smartgwt 1.3 and 2.0.
            My client view contains a ListGrid and a DynamicForm, both bound to the same datasource.
            After adding a record via the form, SimpleGwtRPCDS.executeAdd() gets executed and the call back onSuccess() throws when calling
            processResponse(requestId, response);
            This is not happening if the ListGrid is removed or not connected to the datasource.

            Thanks,
            Dmitriy

            09:29:18.133 [ERROR] [ds0604] Uncaught exception escaped
            com.google.gwt.core.client.JavaScriptException: (null): null
            at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195)
            at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
            at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
            at com.smartgwt.client.data.DataSource.processResponse(DataSource.java)
            at my.client.SimpleGwtRPCDS$2.onSuccess(SimpleGwtRPCDS.java:122)
            at my.client.SimpleGwtRPCDS$2.onSuccess(SimpleGwtRPCDS.java:1)
            at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:216)

            Comment


              Hi sunnyl,
              The full project is attached. I had to append .txt to the archive, as zip is not allowed as attachment.
              Attached Files

              Comment


                Strange, I've just imported the project and its working fine.

                The only thing I needed to do was import the SmartGWT and GWT jars (I didn't have SMARTGWT_HOME set).

                Comment


                  I have repeated my test from scratch and had the same error in Firefox. In IE it is working fine. I did the following:
                  1. Downloaded the latest eclipse JDT: eclipse-java-galileo-SR1-win32.zip
                  2. Installed Google plugin: http://dl.google.com/eclipse/plugin/3.5
                  3. Imported the project, using new workspace.
                  4. Started the app in Development mode using Run As -> Web Application.
                  5. Used form to: put some value to Name field and press Save button.

                  Comment


                    To clarify, I tested only using FF 3.5.6, and it worked as expected. Are you sure theres no references in the project to older GWT/SmartGWT versions perhaps? Can you post up somewhere the entire self contained project with the problem (ie, no references to JARs external to the project, keep it in web-inf/libs).


                    dindeman: I think the GwtRpcDataSource is awesome. I'm planning to post up more real world examples of using it with SmartGWT components (esp combos and grids) later on.

                    Comment


                      RE: JavaScriptException: (null) in DataSource.processResponse after switching to GWT2

                      I have fixed the JavaScriptException: (null), reported earlier, by clearing Firefox Recent History, including cache.
                      Thanks,
                      Dmitriy

                      Comment


                        Using JSON for date fields

                        This is regarding Mnenchev's suggestion of using JSON to avoid having to manually copy the data from your DTO to the ListRecord. His suggestion works fine but, for Date fields, I have a problem since JSON returns the date as a String and JSON Parse does not convert it to a Date Field. The question is where to fix this? Should I fix this case by case when using a Date Field in the execute Fetch method? Is there a way I can come up with a more generic solution and put it in GwtRPCDS when receiving a response? I would appreciate any suggestion on how to come up with a general solution

                        On executeFetch I do:
                        Code:
                        ListGridRecord[] list = new ListGridRecord[size];
                        if (size > 0) {
                        	for (int i = 0; i < result.getRecords().size(); i++) {
                        		if (i >= startIndex && i <= endIndex) {
                        			final JSONObject obj = (JSONObject) JSONParser.parse(result.getRecords().get(i));
                        			ListGridRecord record = new ListGridRecord(obj.getJavaScriptObject());
                        			
                        			list[i - startIndex] = record;
                        		}
                        	}
                        }
                        response.setData(list);
                        On the server I do:

                        Code:
                        final JSON json = new JSON();
                        
                        json.addConvertor(MyDto.class, new JSONPojoConvertor(MyDto.class));
                        String jsondto;
                        
                        jsondto = json.toJSON(new MyDto(batchId, batchDate, batchDesc, batchEntries, bankId));
                        myList.add(jsondto);
                        batchDate is returned as a String in executeFetch

                        Comment


                          How do you configure smartClient to work with a EJB Data Source?

                          Good afternoon.

                          I have an J2EE project which uses EJBs for the persistent layer.

                          I'm trying to use the suggestions here to create a DataSource which would be used to a GWT-RPC Service which in turn calls an EJB SessionBean to return requested data.

                          How do you configure the DataSource to work in this configuration?

                          Specifically, how to you setup the project so that SmartClient knows how to find the source code for the Entity classes. They exist in a separate module (ejb module as opposed to the war module where smartclient lives) and likely exists in a package which does not extend the <smartclient-module/client> structure.

                          When I try to build the project (I'm using netbeans with GWT4NB) I get the error:

                          Code:
                          Validating newly compiled units
                               [ERROR] Errors in 'file:/<path to client/DataSource.java'
                                    [ERROR] Line 62: No source code is available for type <Entity>; did you forget to inherit a required module?
                          I would appreciate your thoughts and comments.

                          Regards,


                          Troi


                          Originally posted by mnenchev
                          This is my entry point:
                          public void onModuleLoad() {

                          ListGridField rowNum = new ListGridField("id", "Id");
                          rowNum.setWidth(65);
                          rowNum.setCellFormatter(new CellFormatter() {
                          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                          return rowNum +"";
                          }
                          });

                          ListGridField mail = new ListGridField("email", 100);

                          final ListGrid listGrid = new ListGrid();
                          rootPanel.add(listGrid);
                          listGrid.setWidth100();
                          listGrid.setHeight100();
                          TestDataSource dataSource = new TestDataSource();
                          listGrid.setAutoFetchData(true);
                          listGrid.setDataSource(dataSource);
                          listGrid.setFields(rowNum, mail);
                          listGrid.setDataPageSize(10);
                          listGrid.fetchData();
                          listGrid.draw();
                          }


                          And this is what i have changed in the datasource:

                          public TestDataSource() {
                          DataSourceField field;
                          field = new DataSourceIntegerField("id", "id");
                          field.setPrimaryKey(true);
                          field.setRequired(false);
                          addField(field);
                          field = new DataSourceTextField("mail", "mail");
                          field.setRequired(true);
                          addField(field);
                          }

                          @Override
                          protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) {
                          int startRow = request.getStartRow();
                          int endRow = request.getEndRow();
                          String sortBy = request.getSortBy();
                          TestServiceAsync service = ServiceUtils.getTestServiceAsync();
                          service.fetch(startRow, endRow, sortBy, new AsyncCallback<List<TestRecord>>() {
                          public void onFailure(Throwable caught) {
                          response.setStatus(RPCResponse.STATUS_FAILURE);
                          processResponse(requestId, response);
                          }

                          public void onSuccess(List<TestRecord> result) {
                          ListGridRecord[] list = new ListGridRecord[result.size()];
                          for (int i = 0; i < list.length; i++) {
                          ListGridRecord record = new ListGridRecord();
                          copyValues(result.get(i), record);
                          list[i] = record;
                          }
                          response.setData(list);
                          processResponse(requestId, response);
                          }
                          });
                          }

                          The rpc is working fine(i tested it before).

                          Comment


                            @teisler You are about to head down a road of having to create a bunch of DTOs (data transfer objects) corresponding to each of your EJBs. If you'd like to avoid this work, take a look at the Pro and Enterprise versions, which avoid this work entirely, and offer dozens of other features you will likewise have to write yourself if you go with GWT-RPC.

                            Comment


                              is it possible to add new record at runtime

                              Hi,
                              I want to be able to update/ add data to a live grid. (that data item may or may not be visible in current view)
                              Case 1:
                              records 1-10 are visible from 50 records and 20 more records got added(or 20 got deleted) at the backend by another process.
                              Case 2:
                              records 1-10 are visible and 5th record got updated/deleted.

                              How do i do this at runtime?(Assuming I somehow get an event for the same in GWT client code)

                              Comment


                                Which one to use?

                                Hi,

                                Being new to smartGWT, I was exploring the datasource possibilities for the databinding. I have built the prototype on the lines of the code snippets picked from the <a href="http://www.smartclient.com/smartgwt/showcase/#main">showcase</a> which was using XML based datasources and static XML files.

                                Coming to the real time databinding, I was exploring the advantages of using one of JSON/XML/GWTRPC Datasources over the other. For one, the GWT RPC implementation looks pretty neat given there are no "appends" as in building Strings and quite clearly pure OO. However, I don't want to consider that alone as a trait to choose the Datasource implementation.

                                Could someone please suggest me which one to go with as in pros and cons of the implementations.



                                Hari.

                                Comment

                                Working...
                                X