Announcement

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

    Can't get Criteria to work

    Hi all,

    First off: thanks so much for this discussion, it helped me a great lot with getting GWT-RPC datasources working.

    The only problem I still have left is fetching data using Criteria. I've looked at and tried the example from this thread with the GWTCriterion class, but I'm getting this error when I'm running it:

    Code:
    [ERROR] com.google.gwt.user.client.rpc.SerializationException
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.SerializerBase.check(SerializerBase.java:161)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:145)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
    [ERROR] 	at nl.kees.test.db.client.util.criteria.GWTCriterion_FieldSerializer.serialize(GWTCriterion_FieldSerializer.java:32)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [ERROR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [ERROR] 	at java.lang.reflect.Method.invoke(Method.java:592)
    [ERROR] 	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    [ERROR] 	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    [ERROR] 	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284)
    [ERROR] 	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.SerializerBase$MethodMap$.serialize$(SerializerBase.java)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.SerializerBase.serialize(SerializerBase.java:147)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize(ClientSerializationStreamWriter.java:199)
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
    [ERROR] 	at nl.kees.test.db.client.admin.AdminDataService_Proxy.fetch(AdminDataService_Proxy.java:52)
    [ERROR] 	at nl.kees.test.db.client.util.DynamicDataSource.executeFetch(DynamicDataSource.java:90)
    [ERROR] 	at nl.kees.test.db.client.util.GwtRpcDataSource.transformRequest(GwtRpcDataSource.java:105)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [ERROR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [ERROR] 	at java.lang.reflect.Method.invoke(Method.java:592)
    [ERROR] 	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    [ERROR] 	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    [ERROR] 	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    [ERROR] 	at java.lang.Thread.run(Thread.java:595)

    I read somewhere that since GWT 2.0 (which I'm using), the IsSerializable is re-introduced instead of the regular Serializable, which might make this old example to crash?

    Does anyone have this working (GWT-RPC fetching with Criteria) in GWT 2.0?

    Thanks for any help!

    Regards,

    Kees.

    Comment


      Ok, so looking at the code of GWT itself, it looks like this error is thrown when I try to serialize a field that can't be serialized.

      The problem still is, I can't figure out what field of GWTCriterion causes this. Is there anyone out there with similar issues and (hopefully) a solution? :)

      Regards,

      Kees.

      Comment


        Originally posted by jzaruba
        I'm not sure how this could possibly work without sending all the data (person, its boss, his boss, his boss, etc... whole db?) in one request. Otherwise your getBoss() call (which IMO happens on the client side) would either always return null OR it would have to make another (synchronous!) request to fetch the boss entity from the server.

        My understanding is that lazy many-to-one relations do not cope with the GWT concept.
        (I would be happy should anyone correct me on this.)
        I have the same problem and i cannot find a solution.
        Is there someone who has already implemented this kinf of datasource ?

        Comment


          Same exact error here, using GWT 2.0.1 and the latest ee trial, but I'm not using a datasource at all, just invoking a Gwt Rpc service directly with

          Code:
          XXXService.Util.getInstance().doit(arg, callback)
          where arg is just an object with a list of other objects, all of which implement Serializable. When I print this with GWT.log I get the extra string "null" after the exception in the stack trace.

          It looks like (http://www.docjar.com/html/api/com/google/gwt/user/client/rpc/impl/SerializerBase.java.html) the "serialize" and later "check" method is getting a null value somehow. Not sure if this is a result of anything related to smartclient or not. I'm planning to experiment with this in another non-smartclient project today to see if I can recreate it there.

          Comment


            reflesh listgrid after deleting a row

            i am using listgrid as following
            Code:
             ListGrid aGrid= new ListGrid();
            	  aGrid.setDataSource(gwtRpcDS);
                      aGrid.setCanEdit(false);
                      aGrid.setAutoFetchData(true);
            gwtRpcDS is a datasource inheriating GwtRpcDataSource with changes as

            Code:
             	@Override
            	protected void executeRemove(final String requestId, DSRequest request,
            			final DSResponse response) {
            		 // Retrieve record which should be removed.
                    JavaScriptObject data = request.getData ();
                    final ListGridRecord rec = new ListGridRecord (data);
                    MyData testRec = new MyData ();
                    copyValues (rec, testRec);
              
                  // We do not receive removed record from server.
                  // Return record from request.
            
                   DataCallAsync<MyData> call = GWT.create(DataCall.class);
                   call.remove (testRec, new AsyncCallback<Void> () {
                        public void onFailure (Throwable caught) {
                        	InfoPane.getInstance().setInfo("failure");
                            response.setStatus (RPCResponse.STATUS_FAILURE);
                            processResponse (requestId, response);
                        }
                        @Override
            			public void onSuccess(Void result) {
                        	InfoPane.getInstance().setInfo("success");
                            ListGridRecord[] list = new ListGridRecord[1];
                            // We do not receive removed record from server.
                            // Return record from request.
                            list[0] = rec;
                            response.setData (list);
                            processResponse (requestId, response);
                        }
            			
            
                    });
            
            
            	}
            when i delete a selected record, it will be removed at server side, but it stays still in the listgrid.
            does anyone know what's wrong with it? how can i take the record off?

            Comment


              Originally posted by weili
              when i delete a selected record, it will be removed at server side, but it stays still in the listgrid.
              does anyone know what's wrong with it? how can i take the record off?
              How do you remove record - via dataSource.remove() ?
              If yes then you have to refresh list grid manually.

              It should work if you remove record via remove field or via listGrid.removeData().

              Comment


                thany you for the rapid answer
                Originally posted by alius
                It should work if you remove record via remove field or via listGrid.removeData().
                i used listGrid.removeData(). my code as following

                Code:
                 DataSource myDS = MyDS.getInstance();
                		
                		final DynamicForm form = new DynamicForm();
                		form.setIsGroup(true);
                		form.setNumCols(4);
                		form.setDataSource(myDS);
                
                		final ListGrid listGrid = new ListGrid();
                		listGrid.setWidth100();
                		listGrid.setHeight(200);
                		listGrid.setDataSource(myDS);
                		listGrid.setAutoFetchData(true);
                		listGrid.addRecordClickHandler(new RecordClickHandler() {
                			public void onRecordClick(RecordClickEvent event) {
                				form.reset();
                				form.editSelectedData(listGrid);
                			}
                		});
                
                		addMember(listGrid);
                		addMember(form);
                
                		IButton button = new IButton("remove selected");
                		button.addClickHandler(new ClickHandler() {
                			public void onClick(ClickEvent event) {
                				ListGridRecord selectedRecord = listGrid.getSelectedRecord();
                				if (selectedRecord != null) {
                					listGrid.removeData(selectedRecord);
                
                				} else {
                					SC.say("Select a record before performing this action");
                				}
                			}
                		});
                		addMember(button);

                Originally posted by alius
                How do you remove record - via dataSource.remove() ?
                If yes then you have to refresh list grid manually.
                i have also attempted to use listGrid.getDataSource().removeData(selectedRecord).
                it failed to remove the record at server side probably because no correct data is passed to executeRemove.

                I can't get data from rec as
                Code:
                JavaScriptObject data = request.getData ();
                        final ListGridRecord rec = new ListGridRecord (data);
                another question
                could you tell how to refresh list grid manually?

                Comment


                  sorry, i forgot to set field as primary key.
                  now it works. thank you

                  Comment


                    Originally posted by sjivan
                    Hi Alius,
                    The idea is that all DataBound components should actually work with the generic Record type. Users can use widget specific record types but they should be interchangeably be able to used to display contents of other DataBound components. So the GwtRpcDataSource should really only be working at the "Record" level so that it can be used with any DataBoundComponent.

                    Sanjiv
                    actually, it doesn't work (for me). Looking at the examples here everybody seems to ignore this issue and simply use ListGridRecords?

                    Code:
                    19:39:44.268 [ERROR] [client] Uncaught exception escaped
                    java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord
                        at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:90)
                        at sun.reflect.GeneratedMethodAccessor25.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:157)
                        at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
                        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)

                    Comment


                      mutiple servlets

                      Hello!

                      First off i would like to thank the people that have contributed to this easy to implement method of using the RPC service.

                      I copied this stuff and changed all the words etc to make one instance of the servlet work for me. Then I went to do another, and ran into some issues with the second one that are baffling me. As far as I can see, everything about the two different servlet's setup is the same, but for the second one I am getting this error. It also sometimes does not occur, maybe 1/10 attempts to run it.

                      Code:
                      09:26:38.798 [ERROR] [webreport] Errors in 'generated://378F78684468FC6219051C845A8AEE79/report/client/dbTableTypes/Report_Array_Rank_1_FieldSerializer.java'
                      The dbTableTypes package contains the "type"DataSource.java and the "type" definition class. I have made sure and implemented Serializable and generated a SerialVersionUID in both "type".java classes.

                      If you need to see more specific information to help me diagnose this problem please just ask. Thanks!

                      Comment


                        Originally posted by Chazinomaha
                        Hello!

                        First off i would like to thank the people that have contributed to this easy to implement method of using the RPC service.

                        I copied this stuff and changed all the words etc to make one instance of the servlet work for me. Then I went to do another, and ran into some issues with the second one that are baffling me. As far as I can see, everything about the two different servlet's setup is the same, but for the second one I am getting this error. It also sometimes does not occur, maybe 1/10 attempts to run it.

                        Code:
                        09:26:38.798 [ERROR] [webreport] Errors in 'generated://378F78684468FC6219051C845A8AEE79/report/client/dbTableTypes/Report_Array_Rank_1_FieldSerializer.java'
                        The dbTableTypes package contains the "type"DataSource.java and the "type" definition class. I have made sure and implemented Serializable and generated a SerialVersionUID in both "type".java classes.

                        If you need to see more specific information to help me diagnose this problem please just ask. Thanks!
                        **EDIT** Nevermind, still have no idea why it works sometimes, and doesn't other times.
                        Last edited by Chazinomaha; 13 Apr 2010, 09:42.

                        Comment


                          Hi everyone

                          To be able to use the GwtRpcDataSource with every possible Record (and no only GridListRecord) as well as with every possible Data Transfer Object without having to rewrite the whole class every time, I wrote a generic GWT-RPC DataSource, called GenericGwtRpcDataSource<D, R, SA>. It is based on the GwtRpcDataSource of Aleksandras.

                          The type-safe abstract class GenericGwtRpcDataSource<D, R, SA>, together with GenericGwtRpcDataSourceService<D> and GenericGwtRpcDataSourceAsync<D>, should greatly simplify your GwtRpcDataSource implementations, so you won't have to care about ClassCastExceptions or to rewrite the whole class every time you need a new DataSource.

                          I' ve created a new thread with more info, as this one is a bit overloaded already:

                          http://forums.smartclient.com/showthread.php?t=10850

                          I thought I should put a pointer in this thread, because maybe this is interesting for some of you.

                          cheers
                          marbot
                          Last edited by marbot; 4 Jun 2010, 12:54.

                          Comment


                            This thread proved very helpfull to me. But I have one small and stupid question. ( Sorry to post it in this intelligent discussion :-) )

                            when is transformRequest method of DataSource is called ? Is it to be called on some onClick event explicitly by developer or is it going to be called by Listgrid on scroll down event of grid ?

                            Reading java api doc for this method did not help me.

                            Thanks.

                            Comment


                              Happens when you scroll in a ListGrid

                              Originally posted by vinayakshukre
                              This thread proved very helpfull to me. But I have one small and stupid question. ( Sorry to post it in this intelligent discussion :-) )

                              when is transformRequest method of DataSource is called ? Is it to be called on some onClick event explicitly by developer or is it going to be called by Listgrid on scroll down event of grid ?

                              Reading java api doc for this method did not help me.

                              Thanks.
                              Happens when you scroll in a ListGrid and also when you modify your ListGrid such as removeData, saveAllEdits, redraw and invalidateCache
                              Last edited by gcstang; 28 Apr 2010, 04:41.

                              Comment


                                Thanks. It means my guess was right.

                                Any way, I could get that example running with bit simple code as follows.

                                Code:
                                class MyEntryPoint{
                                	final ListGrid countryGrid = new ListGrid();    
                                	countryGrid.setShowAllRecords(false);
                                	countryGrid.setDataPageSize(10);
                                	countryGrid.setWidth(500);  
                                	countryGrid.setHeight(200);  
                                	final MyDataSource dataSource = new MyDataSource(greetingService);
                                	countryGrid.setDataSource(dataSource);
                                	countryGrid.setAutoFetchData(true);
                                	RootPanel.get("r1").add(countryGrid);
                                }
                                
                                class MyDataSource extends DataSource{
                                	GreetingServiceAsync service = null;
                                	
                                	
                                
                                	
                                	public MyDataSource(GreetingServiceAsync service){
                                		super();
                                		this.service = service ;
                                		setID("abc");      
                                                          DataSourceField countryNameField = new DataSourceField("countryName", FieldType.TEXT, "Country");  
                                                          DataSourceField countryCodeField = new DataSourceField("countryCode", FieldType.TEXT, "Code");  
                                                          DataSourceField populationField = new DataSourceField("population", FieldType.INTEGER, "Population");
                                                          setFields(countryCodeField,countryNameField,populationField);    
                                                          setClientOnly(true);   
                                        
                                	}
                                	@Override
                                	protected Object transformRequest(DSRequest dsRequest) {
                                		final int iStart = dsRequest.getStartRow();
                                		final int iEnd = dsRequest.getEndRow() ;
                                		System.out.println("Request came to client code for start =  " + iStart + " " +  iEnd + " " + dsRequest.getRequestId());
                                		final String requestId = dsRequest.getRequestId ();
                                                          final DSResponse response = new DSResponse ();
                                                          response.setAttribute ("clientContext", dsRequest.getAttributeAsObject ("clientContext"));
                                                          response.setStatus(0);
                                                          int iDiff = iEnd - iStart ;
                                                          ListGridRecord[] list = new ListGridRecord[iDiff];
                                                          for(int i = 0 , j = iStart ;j< iEnd;i++,j++){
                                        	                  list[i] = new ListGridRecord();
                                        	                  long time = System.currentTimeMillis();
                                        	                  list[i].setAttribute("countryName", "India " +j);
                                        	                  list[i].setAttribute("countryCode", "In_"+j);
                                        	                  list[i].setAttribute("population", time);
                                                          }
                                                          response.setData(list);
                                                          response.setStartRow(iStart);
                                		response.setEndRow(iEnd);
                                		response.setTotalRows(1000);
                                		processResponse(requestId, response);
                                		return dsRequest.getData();
                                		
                                	}
                                	}
                                This code works fine as it generates rows as requested by moving scrollbar of ListGrid. I was happy.

                                Then I thought of replacing row generation logic with one rpc call.

                                So my new code looked like :
                                Code:
                                protected Object transformRequest(DSRequest dsRequest) {
                                		final int iStart = dsRequest.getStartRow();
                                		final int iEnd = dsRequest.getEndRow() ;
                                		System.out.println("Request came to client code for start =  " + iStart + " " +  iEnd + " " + dsRequest.getRequestId());
                                		final String requestId = dsRequest.getRequestId ();
                                                          final DSResponse response = new DSResponse ();
                                                          response.setAttribute ("clientContext", dsRequest.getAttributeAsObject ("clientContext"));
                                                          response.setStatus(0);
                                                          int iDiff = iEnd - iStart ;
                                                          this.service.greetServer(iStart, iEnd, new AsyncCallback<ReportRow[]>(){
                                
                                			public void onFailure(Throwable caught) {
                                				Window.alert("Error while fetching new rows");				
                                			}
                                
                                			public void onSuccess(Row[] result) {
                                				int iTotalLength = result.length ;
                                				
                                				ListGridRecord list[] = new ListGridRecord[iTotalLength];
                                				for(int i=0; i< iTotalLength; i++){
                                					list[i] = new ListGridRecord();
                                					list[i].setAttribute("countryName", result[i].getCountryName());
                                		        	list[i].setAttribute("countryCode", result[i].getCountryCode());
                                		        	list[i].setAttribute("population", result[i].getPopulation());
                                				}				
                                				response.setData(list);
                                				response.setStartRow(iStart);
                                				response.setEndRow(iEnd);
                                				response.setTotalRows(1000);
                                				processResponse(requestId, response);
                                			}        	
                                        });     
                                           return dsRequest.getData();
                                        }

                                This time I found that return statement of transformRequest executes before processResponse() part written in onSuccess() method for that request. This causes it to give error.

                                com.smartgwt.client.core.JsObject$SGWT_WARN: 18:40:42.714:WARN:DataSource:abc:DataSource.processResponse(): Unable to find request corresponding to ID abc$6270, taking no action.

                                It means that return statement of transformRequest method should not execute before completion of onSuccess() method. It makes me think to add Timer logic in my code.

                                But similar logic is working for other people as I have almost copied this code from 5 files attached with first 2-3 posts of this thread. ( GwtRpcDataSource.java and TestDataSource.java ). In this code there is no any logic of Timer etc. So how does that code works and my doesn't ?

                                Also, does this have anything to do with
                                Code:
                                setClientOnly(true);
                                I tried making it as false as given in GwtRpcDataSource.java. But then it gave me error that I dont have Pro version of smartgwt. Is it the case that paging mechanism that I am trying is only available in Pro version and not in LGPL version ?

                                Please help.
                                Thanks.
                                Last edited by vinayakshukre; 28 Apr 2010, 05:48.

                                Comment

                                Working...
                                X