Announcement

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

  • mivola
    replied
    Originally posted by mnenchev
    Nested Datasources?
    Thanks, I'll have a look into this.

    But what about those associations that I do not want to be displayed or changed in the grid? Do those also need to be handled as (hidden) nested datasources?

    Thanks
    Michael

    Leave a comment:


  • mnenchev
    replied
    Nested Datasources?

    Leave a comment:


  • mivola
    replied
    How to handle associations?

    Hi all,

    thanks a lot for this really helpful pattern! I got it working for my project in almost no time!

    But now I came across a problem. My domain objects have different relations to each other (OneToMany, ManyToMany) that are implemented as javax.persistence annotations. E.g. one User has a list of Roles (@ManyToMany(mappedBy="users")).

    When I now create a UserDataSource based on the GwtRpcDataSource, I can load the records and change the primitive members (first name, last name, ...). The changes are also saved properly, but also the list of roles is set to null and therefore deleted.

    My question is: how can I display (and modify) the roles? If that is not possible, how can I at least preserve the existing associations?

    If this problem cannot bo solved this pattern is IMHO quite useless for real-world domains.

    Thanks for your help!!
    Michael

    Leave a comment:


  • lanceweber
    replied
    I just wanted to point out that with the nifty use of generics you can only have to implement this class once. We've got an initial implementation up and running very nicely by using a Resource interface that bridges between Models and SmartGWT constructs.

    Here's a snippet, just enough to get you started thinking about it and yes, this requires the you have a pretty good handle on coding with generics.

    Code:
    public interface HasSmartGWTResources<M extends DTObjectModel> {
    	List<DataSourceField> getDataSourceFields();
    
    	M newModel();
    	ListGridRecord toListGridRecord(M model);
    	M toModel(ListGridRecord record);
    
    	DvTreeNode toTreeNode(M model, String parentid);
    	List<DvTreeNode> toTreeNodeWithChildren(M model, String parentid);
    }
    
    
    public interface DataService<M extends DTObjectModel> extends RemoteService {
    	List<M> fetch(int startIndex, int count);
    	M add(M model);
    	M update(M model);
    	void remove(M model);
    }
    
    
    public interface DataServiceAsync<M extends DTObjectModel> {
    	void fetch(int startIndex, int count, AsyncCallback<List<M>> async);
    	void add(M model, AsyncCallback<M> async);
    	void update(M model, AsyncCallback<M> async);
    	void remove(M model, AsyncCallback<M> async);
    }
    
    
    public class SmartGWTDataSource<M extends DTObjectModel, R extends HasSmartGWTResources<M>, S extends DataService<M>> extends DataSource {
    	private HasSmartGWTResources<M> resource;
    	private DataServiceAsync<M> service;
    	
        /**
         * Creates new data source which communicates with server by GWT RPC.
         * It is normal server side SmartClient data source with data protocol
         * set to <code>DSProtocol.CLIENTCUSTOM</code> ("clientCustom" - natively
         * supported by SmartClient but should be added to smartGWT) and with data
         * format <code>DSDataFormat.CUSTOM</code>.
         */
    	@SuppressWarnings("unchecked")
    	public SmartGWTDataSource(HasSmartGWTResources<M> resource, Class<S> serviceClass) {
    		super();
            setDataProtocol (DSProtocol.CLIENTCUSTOM);
            setDataFormat (DSDataFormat.CUSTOM);
            setClientOnly (false);
    		this.resource = resource;
    		service = (DataServiceAsync<M>) GWT.create(serviceClass);
    		for (DataSourceField field: resource.getDataSourceFields()) {
    			addField(field);
    		}
    		GWT.log("SourcebookDataSource() initialized.", null);
    	}
    
    .
    .
    .
    }

    Leave a comment:


  • felixx
    replied
    Thanks Aleksandras. Yes, response.setAttribute ("data", list); works fine.

    Leave a comment:


  • sjivan
    replied
    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

    Leave a comment:


  • alius
    replied
    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!

    Leave a comment:


  • alius
    replied
    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

    Leave a comment:


  • felixx
    replied
    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!

    Leave a comment:


  • jhudson8
    replied
    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

    Leave a comment:


  • alius
    replied
    Hi Joe,

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

    Aleksandras

    Leave a comment:


  • jhudson8
    replied
    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) {
    	}
    }

    Leave a comment:


  • mnenchev
    replied
    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.

    Leave a comment:


  • bitblaster
    replied
    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?

    Leave a comment:


  • mnenchev
    replied
    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();

    Leave a comment:

Working...
X