Announcement

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

    #46
    Well I just added this to my Dropbox public folder so you can direct download without all the ads/limits, whatever from free sevices from here:
    http://dl.getdropbox.com/u/335287/TestAdvDataSource.zip

    For any updates for the file, just send it to me and I'll update. ( mihai.ile on gmail.com )

    Comment


      #47
      Hello,

      I just tried to used the GwtRpcDataSource Class.
      Almost all things works fine, but I am not able to refresh the content of the DataSource with attendeesDataSource.fetchData();

      My ListGrid looks like
      Code:
      attendeesList = new ListGrid();
      // list.setWidth(500);
      attendeesList.setHeight100();
      attendeesList.setAlternateRecordStyles(true);
      attendeesList.setShowAllRecords(true);
      attendeesDataSource = new AttendeesDataSource();
      attendeesList.setDataSource(attendeesDataSource);
      attendeesList.setAutoFetchData(true);
      attendeesList.setCanEdit(false);
      and my DataSource Class
      Code:
      public class AttendeesDataSource extends GwtRpcReadOnlyDataSource {
      
      		private List<Attendee> attendeeList;
      		
      		public AttendeesDataSource() {
      			  
      
      		        
      			DataSourceField field;
      			field = new DataSourceTextField("name", "Name");
      			field.setRequired(true);
      			addField(field);
      			
      			field = new DataSourceTextField("email", "Email");
      			field.setRequired(true);
      			addField(field);
      			
      			field = new DataSourceTextField("active", "Aktiv");
      			field.setRequired(true);
      			addField(field);
      			
      			field = new DataSourceTextField("status", "Status");
      			field.setRequired(true);
      			addField(field);
      			/*
      			field = new DataSourceIntegerField ("ID", "ID");
      	        field.setPrimaryKey (true);
      	        addField(field);*/
      		}
      
      		@Override
      		protected void executeFetch(final String requestId,
      				final DSRequest request, final DSResponse response) {
      			System.out.println("--TODO executeFetch");
      			ModeratorService.Util.getInstance().getAttendees(study.getIdStudy(),
      					new AsyncCallback<List<Attendee>>() {
      
      						public void onFailure(Throwable caught) {
      							response.setStatus(RPCResponse.STATUS_FAILURE);
      							processResponse(requestId, response);
      						}
      
      						public void onSuccess(List<Attendee> result) {
      							//damit wir nicht immer neu laden müssen
      							attendeeList = result;
      
      							//attendeesDataSource.
      							// Calculating size of return list
      							int size = result.size();
      							
      							ListGridRecord[] list = new ListGridRecord[size];
      							for (int i = 0; i < result.size(); i++) {
      								ListGridRecord record = new ListGridRecord();
      								Attendee a = result.get(i);
      								System.out.println(a.getName());
      								record.setAttribute("ID", a.getIdAttendee());
      								record.setAttribute("name", a.getName());
      								record.setAttribute("email", a.getEmail());
      								record.setAttribute("active", a.isActive()?"JA":"NEIN");
      								record.setAttribute("status", a.getStatus().name());
      								list[i] = record;
      							}
      							response.setData(list);
      							//response.setTotalRows(result.size());
      							processResponse(requestId, response);
      						}
      					});
      
      		}
      
      public abstract class GwtRpcReadOnlyDataSource
          extends GwtRpcDataSource {
      
      	@Override
      	protected void executeAdd(String requestId, DSRequest request,
      			DSResponse response) {
      	}
      
      	@Override
      	protected void executeRemove(String requestId, DSRequest request,
      			DSResponse response) {
      	}
      
      	@Override
      	protected void executeUpdate(String requestId, DSRequest request,
      			DSResponse response) {
      	}
      }
      The service ModeratorService.Util.getInstance().getAttendees was invoked every time I pressed the refreh button. The received data are fine.
      For me it seems that the GridList does not refresh the content. I tried to use the refresh Functioon of the ListGrid as well, but it does not work either.

      Does anyone have a good idea?
      Thanks a lot

      Comment


        #48
        did you try to call listGrid.invalidadecache and then listgrid.fetchdata?

        Comment


          #49
          You are right!
          I forgot to invoke invalidadecache.
          Now it works fine!

          Comment


            #50
            I have a question. If i want every updated record to be removed from the grid respectively from the datasource without to make new fetch from the server, how can i do that? for example i have a set of records fetch from the server that pass given criteria for example foo = true(all records with property foo = true are displayed). Also i display checkbox that is marked. So if the user uncheck some record it must be removed from the view grid (and the datasource?) without to invalidate the cash and to force fetchData();

            Comment


              #51
              Originally posted by mnenchev
              I have a question. If i want every updated record to be removed from the grid respectively from the datasource without to make new fetch from the server, how can i do that? for example i have a set of records fetch from the server that pass given criteria for example foo = true(all records with property foo = true are displayed). Also i display checkbox that is marked. So if the user uncheck some record it must be removed from the view grid (and the datasource?) without to invalidate the cash and to force fetchData();
              I don't understand well you question:
              1) Do you want to remove the rows immediately when you uncheck the checkboxes or you want uncheck the checkboxes and then press a "Remove" button?
              2) Do you want to remove the rows only client side or the server must be aware of your changes? In this latter case, how can you be sure (without doing a new fetch) that someone else didn't remove other rows in the meantime and so that you are viewing the real data?

              Comment


                #52
                Well, you are right for the 2). But i want to keep in the list grid only records that pass where clause for example booleanFoo = true (in the database). And if the user uncheck booleanFoo for 3 records and pres update their booleanFoo is updated in the database and they are removed from the list grid why should i force new fetch if i know what i updated and what i should remove from the listgrid. The application is admin iterface that will not be used from 2 or more user simultaneously, so making new fetch is unneeded.

                Comment


                  #53
                  having trouble with GwtRpcDataSource

                  Hello, I'm trying to use the GwtRpcDataSource (thank you by the way) and I think I am missing something. Any help would be appreciated.

                  The problem that I am having is the executeFetch is never being called (and the grid never shows any data). I'm sure I'm missing something stupid but I just can't figure out what it is. Thanks.

                  Joe

                  Here is my module code:
                  Code:
                  		ListGrid grid = new ListGrid();
                  		UserDataSource dataSource = new UserDataSource();
                  		grid.setFields(dataSource.createGridFields());
                  		grid.setDataSource(dataSource);
                  		grid.setWidth(500);
                  		grid.setAlternateRecordStyles(true);
                  		grid.setShowAllRecords(false);
                  		addChild(grid);
                  Here is my data source
                  Code:
                  public class UserDataSource extends GwtRpcDataSource {
                  
                  	public ListGridField[] createGridFields() {
                  		return new ListGridField[] {
                  				new ListGridField("id", 10),
                  				new ListGridField("firstName", 30),
                  				new ListGridField("lastName", 30),
                  				new ListGridField("emailAddress", 30)
                  		};
                  	}
                  
                  	@Override
                  	protected void executeAdd(String requestId, DSRequest request,
                  			DSResponse response) {
                          DataSourceField field;
                          field = new DataSourceIntegerField ("id", "Id");
                          field.setPrimaryKey (true);
                          // AutoIncrement on server.
                          field.setRequired (false);
                          addField (field);
                          field = new DataSourceTextField ("firstName", "First Name");
                          field.setRequired (true);
                          addField (field);
                          field = new DataSourceDateField ("lastName", "Last Name");
                          field.setRequired (true);
                          addField (field);
                          field = new DataSourceDateField ("emailAddress", "Email Address");
                          field.setRequired (true);
                          addField (field);
                  	}
                  
                  	@Override
                  	protected void executeFetch(final String requestId, final DSRequest request,
                  			final DSResponse response) {
                  		// if I set a breakpoint here - this is never called
                  		int startRow = toInt(response.getStartRow());
                  		int endRow = toInt(response.getEndRow());
                  		int pageSize = endRow - startRow;
                  		Service.user().findAll(startRow, pageSize, new AsyncCallback<ArrayList<User>>() {
                  			public void onSuccess(ArrayList<User> 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);
                  			};
                  			public void onFailure(Throwable caught) {
                  				response.setStatus(RPCResponse.STATUS_FAILURE);
                  				processResponse(requestId, response);
                  			};
                  		});
                  	}
                  
                      private static void copyValues (User from, ListGridRecord to) {
                          to.setAttribute ("id", from.getId ());
                          to.setAttribute ("firstName", from.getFirstName());
                          to.setAttribute ("lastName", from.getLastName());
                          to.setAttribute ("emailAddress", from.getEmailAddress());
                      }
                  
                  	@Override
                  	protected void executeRemove(String requestId, DSRequest request,
                  			DSResponse response) {
                  	}
                  
                  	@Override
                  	protected void executeUpdate(String requestId, DSRequest request,
                  			DSResponse response) {
                  	}
                  }

                  Comment


                    #54
                    Hi Joe,

                    Either you have to manually call grid.fetchData () or you have to set grid.setAutoFetchData (true).

                    Aleksandras

                    Comment


                      #55
                      That's great! Thank you very much.

                      One other question - should I be setting the total record count so the grid "knows" how large it should be when it is using server-side paging?

                      If so, how is this done?

                      Thanks.

                      Joe

                      Comment


                        #56
                        Hi,
                        Has anyone tried to use the GwtRpcDatSource with a TileGrid?
                        I just can't make it to work and the following exception shows up:
                        [ERROR] Uncaught exception escaped
                        java.lang.ClassCastException: com.smartgwt.client.widgets.grid.ListGridRecord cannot be cast to com.smartgwt.client.widgets.tile.TileRecord at com.smartgwt.client.widgets.tile.TileRecord.getOrCreateRef(TileRecord.java:69) at com.smartgwt.client.data.DataSource.processResponse(Native Method) at mm.ui.client.AssetsDataSource$1.onSuccess(AssetsDataSource.java:52) at mm.ui.client.AssetsDataSource$1.onSuccess(AssetsDataSource.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 com.smartgwt.client.widgets.BaseWidget.draw(Native Method) at mm.ui.client.MainEntryPoint.onModuleLoad(MainEntryPoint.java:138)

                        More details are in this thread
                        http://forums.smartclient.com/showthread.php?t=5086
                        Any idea/comment? Thanks!

                        Comment


                          #57
                          Originally posted by jhudson8
                          That's great! Thank you very much.

                          One other question - should I be setting the total record count so the grid "knows" how large it should be when it is using server-side paging?

                          If so, how is this done?

                          Thanks.

                          Joe
                          Here is an example:

                          http://forums.smartclient.com/showpost.php?p=19473&postcount=15

                          Aleksandras

                          Comment


                            #58
                            Hi,

                            Problem is that response.setData () accepts only ListGridRecord[].

                            (Question to Sanjiv: if DSResponse is quite general object, DataSource objects are used not only in ListGrid - why it accepts only one type of record? Possible solutions would be:
                            1. accept Record[];
                            2. add setData methods with different parameters.
                            )


                            You can try to overcome this (I haven't tried it myself):

                            Create TileRecord[] (fill it with data from List you've got from server).
                            Instead of response.setData (list) use response.setAttribute ("data", list);

                            Hope that helps,
                            Aleksandras

                            Originally posted by felixx
                            Hi,
                            Has anyone tried to use the GwtRpcDatSource with a TileGrid?
                            I just can't make it to work and the following exception shows up:
                            [ERROR] Uncaught exception escaped
                            java.lang.ClassCastException: com.smartgwt.client.widgets.grid.ListGridRecord cannot be cast to com.smartgwt.client.widgets.tile.TileRecord at com.smartgwt.client.widgets.tile.TileRecord.getOrCreateRef(TileRecord.java:69) at com.smartgwt.client.data.DataSource.processResponse(Native Method) at mm.ui.client.AssetsDataSource$1.onSuccess(AssetsDataSource.java:52) at mm.ui.client.AssetsDataSource$1.onSuccess(AssetsDataSource.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 com.smartgwt.client.widgets.BaseWidget.draw(Native Method) at mm.ui.client.MainEntryPoint.onModuleLoad(MainEntryPoint.java:138)

                            More details are in this thread
                            http://forums.smartclient.com/showthread.php?t=5086
                            Any idea/comment? Thanks!

                            Comment


                              #59
                              Originally posted by alius
                              Hi,

                              Problem is that response.setData () accepts only ListGridRecord[].

                              (Question to Sanjiv: if DSResponse is quite general object, DataSource objects are used not only in ListGrid - why it accepts only one type of record? Possible solutions would be:
                              1. accept Record[];
                              2. add setData methods with different parameters.
                              )
                              Hi Aleksandras,
                              You're right, I'll change the API's to accept Record.

                              Sanjiv

                              Comment


                                #60
                                Thanks Aleksandras. Yes, response.setAttribute ("data", list); works fine.

                                Comment

                                Working...
                                X