Announcement

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

    ListGrid update data (using RPC)

    Ok from the other threads I managed to use RPC and DadaSource using setTestData(). Thank you.

    Now I don't know why when I edit something in the ListGrid, on ENTER the edited cells returns to it's previous value.

    my DataSource is:

    Code:
    public class TabelaColunasDS extends DataSource {
    
    	public TabelaColunasDS(ArrayList<BaseBean> asColunas) {
    		setClientOnly(true);
    		
    		DataSourceTextField tf_chvP = new DataSourceTextField("chvP");
    		DataSourceTextField tf_nome = new DataSourceTextField("nome");
    		DataSourceTextField tf_tipo = new DataSourceTextField("tipo");
    		DataSourceTextField tf_isObrigatorio = new DataSourceTextField("isObrigatorio");
    		DataSourceTextField tf_isPk = new DataSourceTextField("isPk");
    		setFields(tf_chvP, tf_nome, tf_tipo, tf_isObrigatorio, tf_isPk);
    
    		loadData(asColunas);
    
    	}
    	
    	private void loadData(ArrayList<BaseBean> asColunas) {
    		ListGridRecord[] camposTabela = new ListGridRecord[asColunas.size()];
    		for (int i = 0; i < asColunas.size(); i++) {
    			BaseBean baseBean = asColunas.get(i);
    			if (baseBean instanceof TableField) {
    				TableField tf = (TableField) baseBean;
    				camposTabela[i] = new ListGridRecord();
    				camposTabela[i].setAttribute("chvP", tf.getChvP());
    				camposTabela[i].setAttribute("nome", tf.getNome());
    				camposTabela[i].setAttribute("tipo", tf.getTipo());
    				camposTabela[i].setAttribute("isObrigatorio", tf.isObrigatorio());
    				camposTabela[i].setAttribute("isPk", tf.getPK());
    				camposTabela[i].setAttribute("baseBean", tf);
    			}
    		}
    		setTestData(camposTabela);
    	}
    	
    }
    and my ListGrid is:

    Code:
    	private void initColunas(ArrayList<BaseBean> asColunas) {
    		TabelaColunasDS tabelaColunasDS = new TabelaColunasDS(asColunas);
    
    		ListGrid listGrid = new ListGrid();
    		listGrid.setAutoFetchData(true);
    		listGrid.setCanEdit(true);
    
    		listGrid.setDataSource(tabelaColunasDS);
    
    		ListGridField lgfChvP = new ListGridField("chvP", "ChaveP");
    		ListGridField lgfNome = new ListGridField("nome", "Nome");
    		ListGridField lgfTipo = new ListGridField("tipo", "Tipo");
    		ListGridField lgfIsPk = new ListGridField("isPk", "isPk");
    		listGrid.setFields(lgfChvP, lgfNome, lgfTipo, lgfIsPk);
    
    		addItem(listGrid);
    	}
    I was trying to follow the example http://www.smartclient.com/smartgwt/...id_editing_row but using RPC instead, there when I hit enter the values remain changed. Not in my above sample, it could be that I'm missing something stupid really...

    #2
    Ok, I found the error!
    I needed to set:

    Code:
    tf_chvP.setPrimaryKey(true);
    In the datasource class.

    Now I got further, and I can't add new row:

    Code:
    	IButton newB = new IButton("Adicionar");
    		newB.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				listGrid.startEditingNew();
    			}
    		});
    it gives me an exception:

    Code:
    Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): 'null' é nulo ou não é um objecto
     number: -2146823281
     description: 'null' é nulo ou não é um objecto
    	at com.smartgwt.client.widgets.grid.ListGrid.getBaseStyle(Native Method)
    	at com.smartgwt.client.widgets.grid.ListGrid.startEditingNew(Native Method)
    	at pt.gedi.base.interfaceClient.client.TableForm$2.onClick(TableForm.java:141)
    	at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:100)
    	at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
    	at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:59)
    	at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:47)
    	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:165)] in http://localhost:8888/pt.gedi.base.interfaceClient.EntryPoint/hosted.html?pt_gedi_base_interfaceClient_EntryPoint, line 20
    Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): 'null' é nulo ou não é um objecto
     number: -2146823281
     description: 'null' é nulo ou não é um objecto
    	at com.smartgwt.client.widgets.grid.ListGrid.getBaseStyle(Native Method)] in http://localhost:8888/pt.gedi.base.interfaceClient.EntryPoint/hosted.html?pt_gedi_base_interfaceClient_EntryPoint, line 14
    I hope someone could give me some tips to pass this error also...

    Comment


      #3
      Fixed in SVN. getBaseStyle() is passed in null record in the override when ListGrid. startEditingNew() is called because the record is in the process of being created. I wasn't handling this case but it should work fine now.

      Sanjiv

      Comment


        #4
        heheh only revision 252 fixed it, thank you.

        Comment


          #5
          Originally posted by mihai007
          Ok from the other threads I managed to use RPC and DadaSource using setTestData(). Thank you.
          I'm using addData() removeData() of DataSource
          Not sure of the differences with setTestData() so I tried your example:

          Code:
          				ListGridRecord[] camposTabela = new ListGridRecord[1];
          				
          				camposTabela[0] = new ListGridRecord();
          				camposTabela[0].setAttribute("name", "a");
          				camposTabela[0].setAttribute("email", "b");
          				camposTabela[0].setAttribute("role", "c");
          
          				getDataSource().setTestData(camposTabela);
          datasource and grid are created like yours.

          but I had this exception:

          Code:
          Exception occurred in MethodDispatch.invoke:
          Exception in thread "main" java.lang.ClassCastException
          	at java.lang.Class.cast(Class.java:2990)
          	at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:122)
          	at com.google.gwt.dev.shell.moz.MethodDispatch.invoke(MethodDispatch.java:70)
          	at com.google.gwt.dev.shell.moz.LowLevelMoz._invoke(Native Method)
          	at com.google.gwt.dev.shell.moz.LowLevelMoz.invoke(LowLevelMoz.java:131)
          	at com.google.gwt.dev.shell.moz.ModuleSpaceMoz.doInvoke(ModuleSpaceMoz.java:98)
          	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.core.BaseClass.setProperty(BaseClass.java)
          	at com.smartgwt.client.core.BaseClass.setAttribute(BaseClass.java:283)
          	at com.smartgwt.client.data.DataSource.setTestData(DataSource.java:1056)
          	at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper.setTestRecord(UserGridHelper.java:122)
          	at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper$1.onSuccess(UserGridHelper.java:92)
          	at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper$1.onSuccess(UserGridHelper.java:1)
          	at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
          	at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:254)
          	at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:226)
          	at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:217)
          	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.moz.MethodDispatch.invoke(MethodDispatch.java:80)
          	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
          	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1428)
          	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
          	at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
          	at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
          	at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
          [FATAL] Uncaught Exception:
          java.lang.RuntimeException:
          Failed to invoke native method: @com.smartgwt.client.core.BaseClass::setProperty(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;) with 2 arguments.
              at com.google.gwt.dev.shell.moz.LowLevelMoz.invoke(LowLevelMoz.java:132)
              at com.google.gwt.dev.shell.moz.ModuleSpaceMoz.doInvoke(ModuleSpaceMoz.java:98)
              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.core.BaseClass.setProperty(BaseClass.java)
              at com.smartgwt.client.core.BaseClass.setAttribute(BaseClass.java:283)
              at com.smartgwt.client.data.DataSource.setTestData(DataSource.java:1056)
              at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper.setTestRecord(UserGridHelper.java:122)
              at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper$1.onSuccess(UserGridHelper.java:92)
              at com.vodafone.global.ngp.editorial.client.firstSample.UserGridHelper$1.onSuccess(UserGridHelper.java:1)
              at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
              at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:254)
              at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:226)
              at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:217)
              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.moz.MethodDispatch.invoke(MethodDispatch.java:80)
              at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
              at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1428)
              at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
              at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
              at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
              at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
          any idea why?

          Comment


            #6
            Which build are you using?

            Comment


              #7
              Originally posted by sjivan
              Which build are you using?

              I'm using the maven pom. So I think it's the 17 dec one.
              I can try with the nightly build now, to test.
              Btw, do you plan to put also the nightly builds on maven? or creating a new build soon?

              using a local jar with Maven is possible but...

              Comment


                #8
                1. Can you try using the latest build.

                2. If the error persists can you post a standalone test that can be run locally.

                Thanks.

                Comment


                  #9
                  Originally posted by smartgwt.dev
                  1. Can you try using the latest build.

                  2. If the error persists can you post a standalone test that can be run locally.

                  Thanks.
                  I've just checked with issue 65, if I setTestData() before connecting the grid it works fine.
                  Now I'll try with latest nightly build

                  Comment


                    #10
                    Originally posted by uberto
                    I've just checked with issue 65, if I setTestData() before connecting the grid it works fine.
                    Now I'll try with latest nightly build
                    With yesterday nighly build it works fine.

                    But I have a problem, after I reset the data with setTestData() the grid don't display the new data, also grid.redraw() and grid.fetchData() don't work.
                    Instead I had to fetch the datasource to make it work.

                    Code:
                    gridHelper.getDataSource().fetchData(null, new DSCallback() {
                    		public void execute(DSResponse response, Object rawData, DSRequest request) {
                    			gridHelper.getGrid().setData(response.getData());
                    					};
                    		});
                    am I missing something stupid?

                    Comment


                      #11
                      this is strange, as I refresh the data source data calling again setTestData(new values here) and changes are visible in my list grid.
                      Could it be because of this?
                      Code:
                      	listGrid.setAutoFetchData(true);
                      Without this line even if I setTestData(new data) in data source, the grid does not update...

                      Comment


                        #12
                        A DataSource with clientOnly:true is simulating a server-side store. Calling setTestData() is like having the complete dataset change on the server: the grid doesn't know about it and believes it has a complete cache.

                        To get rid of your cache, call setData() with an empty array, then call fetchData() again.

                        Comment


                          #13
                          Originally posted by Isomorphic
                          A DataSource with clientOnly:true is simulating a server-side store. Calling setTestData() is like having the complete dataset change on the server: the grid doesn't know about it and believes it has a complete cache.

                          To get rid of your cache, call setData() with an empty array, then call fetchData() again.

                          Thank you for the explanation.
                          And also for the nightly maven rep!

                          Comment


                            #14
                            I'm having the same problem of not being able to replace the data using setTestData().
                            As I need the data for a calendar, i can't use the mentioned way to empty the cache and reload everything from store.
                            Calendar has no fetchData() method to explicitly load data from a DataSource.

                            Is there a way to use setTestData() for a DataSource and propagate the changes to a calendar?

                            Comment


                              #15
                              Originally posted by Isomorphic
                              To get rid of your cache, call setData() with an empty array, then call fetchData() again.
                              Do you mean on the grid?
                              to make it work I had to call setAutoFetchData(false).
                              Is this the intended behaviour?

                              Comment

                              Working...
                              X