Announcement

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

  • mitekphoto
    replied
    Adding (updating) muiltiple records with GWT-RPC

    We have adopted the GWT-RPC code for our project, and it works great. I really like it. Here is a fragment of code from our adopted GWT-RPC implementation class :

    Code:
    		service.add(getRecordType(),getValuesAsMap(new ListGridRecord(data)),new AsyncCallback<HashMap>() {
    			public void onFailure(Throwable caught) {
    				response.setStatus(RPCResponse.STATUS_FAILURE);
    				processResponse(requestId,response);
    			}
    			public void onSuccess(HashMap result) {
    				switch(type.getDataSourceType()) {
    					case GRID:
    						ListGridRecord[] list = new ListGridRecord[1];
    						ListGridRecord newRec = new ListGridRecord();
    						copyValues(result,newRec);
    						list[0] = newRec;
    						response.setData(list);
    						break;
    					case TREE:
    						TreeNode[] tree = new TreeNode[1];
    						TreeNode node = new TreeNode();
    						copyValues(result,node);
    						tree[0] = node;
    						response.setData(tree);
    						break;
    					default:
    						SC.logWarn("unknown datasource type: " + recordType.getDataSourceType());							
    				}
    				processResponse(requestId,response);
    			}
    		});
    and here lies my question. Notice the code:

    Code:
    						ListGridRecord[] list = new ListGridRecord[1];
    						ListGridRecord newRec = new ListGridRecord();
    						copyValues(result,newRec);
    						list[0] = newRec;
    						response.setData(list);
    						break;
    It creates a one-record-long array of Records to be returned via setData() to the grid. The GWT-RPC behavior is that whatever is in that record, will be added as a new record (or, replace the record with same key in case of update) to the grid.

    I wonder if it would be possible to add multiple records in one shot, and have them be added to the grid by creating & returning an array of not just one record, like above, but of several records ? Are there any things to know or be aware of when implementing such a solution ? Would that approach work for the update() function as well ?

    Did anyone successfully implement that approach ?

    D.

    Leave a comment:


  • jballh
    replied
    It works! Great! I'll see if I can put it to good use.

    Leave a comment:


  • weeshin
    replied
    Can author add the GwtRpcDataSource into SmartGWT?
    User will be easy to follow up the latest version.
    Thanks.

    Leave a comment:


  • jdanzer
    replied
    Ok to answer my own question - should have read this thread more closely - looks like the object needs to be cast in the GwtRpcDataSource, ie, something like:

    Code:
     protected void copyValues(T from, ListGridRecord to) {
        	DataSourceField[] fields = getFields();
    
        	for (DataSourceField field : fields) {
        		String name = field.getName();
        		Object value = getValueOf(from, name);
        		if (value instanceof Integer){
        			to.setAttribute(name, ((Integer) value).intValue());
        		}
        		else if (value instanceof Date){
        			to.setAttribute(name, (Date) value);
        		}
        		else {
        			to.setAttribute(name, value);
        		}
        	}
    }
    Anyway, keep up the excellent work!

    jd

    Leave a comment:


  • jdanzer
    replied
    trouble sorting locally

    I'm having trouble sorting locally with the TestAdvSourceExample.zip project, with SmartGWT 1.1 and GWT 1.6.4. I was wondering if someone could suggest an answer.

    I have remote searches with sorting working, but even from the example, if I return fewer results than the data page size, everything sorts as a string, regardless of the actual type (integer, date, etc).

    For example, I take the example and modify the TestServiceImpl to:

    Code:
    	static {
    		list = new ArrayList<TestRecord>();
    		TestRecord record;
    		for (int i = 1; i <= 40; i++) {
    			record = new TestRecord();
    			record.setId(i);
    			record.setName("Name " + i);
    			record.setDate(new Date(200 + i, 1, 1) );
    			list.add(record);
    		}
    	}
    And sorting doesn't work anymore (returning only 40 items lets it go into client-side sorting, I think). To be clear, it sorts, but it sorts everything as a string, so 11 is considered less than 4, for example.

    I tried in the entry point to add:

    Code:
                    ListGridField[] fields = new ListGridField[3];
    		fields[0] = new ListGridField("id", "ID");
    		fields[0].setType(ListGridFieldType.INTEGER);
    		
    		fields[1] = new ListGridField("name", "name");
    		fields[1].setType(ListGridFieldType.TEXT);
    		
    		fields[2] = new ListGridField("date", "Date of Birth");
    		fields[2].setType(ListGridFieldType.DATE);
    		
    		listGrid.setFields(fields);
    ...to no avail. I have also tried adding sort normalizers and they don't get called, it seems.

    Anyone have any suggestions? Am I going from the wrong example, or missing something silly?

    Much thanks in advance,

    jd
    Last edited by jdanzer; 22 Jun 2009, 17:12.

    Leave a comment:


  • ynaik
    replied
    Originally posted by ynaik
    I don;t the see the data inside Grid, I see only the Header fields.
    here my client code

    public void onModuleLoad() {


    // TODO Auto-generated method stub
    TestDataSource myDataSource = new TestDataSource();

    final ListGrid listGrid = new ListGrid();
    //listGrid.setAutoFetchData(true);
    listGrid.setShowFilterEditor(true);
    listGrid.setShowAllRecords(false);
    listGrid.setAlternateRecordStyles(true);
    listGrid.setFilterOnKeypress(false);
    listGrid.setDataPageSize(60);
    listGrid.setWidth100();
    listGrid.setHeight("*");
    listGrid.setCanEdit(true);
    listGrid.setEditEvent(ListGridEditEvent.CLICK);
    listGrid.setEditByCell(true);

    final FilterBuilder filterBuilder = new FilterBuilder();
    //filterBuilder.setTopOperatorAppearance(TopOperatorAppearance.RADIO);

    IButton filterButton = new IButton("Filter");
    filterButton.setOverflow(Overflow.CLIP_V);

    filterButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    listGrid.invalidateCache();
    listGrid.fetchData(filterBuilder.getCriteria());
    }
    });

    filterBuilder.setDataSource(myDataSource);
    listGrid.setDataSource(myDataSource);
    listGrid.fetchData();
    //listGrid.fetchData(filterBuilder.getCriteria());
    //VStack vStack = new VStack(10);
    VLayout vStack = new VLayout();
    vStack.setWidth100();
    vStack.setHeight100();

    vStack.addMember(filterBuilder);
    vStack.addMember(filterButton);
    vStack.addMember(listGrid);

    vStack.draw();

    }

    }

    I tried both the options listGrid.setAutoFetchData(true); & listGrid.fetchData();

    Pls help.
    Thanks
    Thanks , It worked..

    Leave a comment:


  • ynaik
    replied
    grid shows no data

    I don;t the see the data inside Grid, I see only the Header fields.
    here my client code

    public void onModuleLoad() {


    // TODO Auto-generated method stub
    TestDataSource myDataSource = new TestDataSource();

    final ListGrid listGrid = new ListGrid();
    //listGrid.setAutoFetchData(true);
    listGrid.setShowFilterEditor(true);
    listGrid.setShowAllRecords(false);
    listGrid.setAlternateRecordStyles(true);
    listGrid.setFilterOnKeypress(false);
    listGrid.setDataPageSize(60);
    listGrid.setWidth100();
    listGrid.setHeight("*");
    listGrid.setCanEdit(true);
    listGrid.setEditEvent(ListGridEditEvent.CLICK);
    listGrid.setEditByCell(true);

    final FilterBuilder filterBuilder = new FilterBuilder();
    //filterBuilder.setTopOperatorAppearance(TopOperatorAppearance.RADIO);

    IButton filterButton = new IButton("Filter");
    filterButton.setOverflow(Overflow.CLIP_V);

    filterButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
    listGrid.invalidateCache();
    listGrid.fetchData(filterBuilder.getCriteria());
    }
    });

    filterBuilder.setDataSource(myDataSource);
    listGrid.setDataSource(myDataSource);
    listGrid.fetchData();
    //listGrid.fetchData(filterBuilder.getCriteria());
    //VStack vStack = new VStack(10);
    VLayout vStack = new VLayout();
    vStack.setWidth100();
    vStack.setHeight100();

    vStack.addMember(filterBuilder);
    vStack.addMember(filterButton);
    vStack.addMember(listGrid);

    vStack.draw();

    }

    }

    I tried both the options listGrid.setAutoFetchData(true); & listGrid.fetchData();

    Pls help.
    Thanks


    Originally posted by alius
    Hi Joe,

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

    Aleksandras

    Leave a comment:


  • smartgwt.dev
    replied
    Those warnings can be ignored. An issue has been reported for it, and these warnings should disappear with GWT 2.0, when OOPHM (out of process hosted mode) is supported.

    Leave a comment:


  • second_comet
    replied
    error when running bitblaster example?

    did anyone get error in hosted mode when running bitblaster example ?

    WARN] Malformed JSNI reference 'constructor'; expect subsequent failures
    java.lang.NoSuchFieldError: constructor
    at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getDispId(CompilingClassLoader.java:122)
    at com.google.gwt.dev.shell.CompilingClassLoader.getDispId(CompilingClassLoader.java:574)
    at com.google.gwt.dev.shell.mac.WebKitDispatchAdapter.getField(WebKitDispatchAdapter.java:68)
    at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2909)
    at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
    at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
    at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
    at com.google.gwt.dev.GWTShell.main(GWTShell.java:140)

    Leave a comment:


  • cdelhorbe
    replied
    TreeGrid lazy load

    Hi,
    Here is my attempt to lazy load a tree using the GwtRpcDataSource (great job btw!). Not the cleanest code, but it works. Hope it helps

    Code:
    	public class FoldersDataSource extends GwtRpcDataSource {
    
    		private static final String NAME_FIELD = "name";
    
    		public FoldersDataSource() {
    			setID("folders");
    			setTitle("Dossiers");
    			DataSourceTextField nameField = new DataSourceTextField(NAME_FIELD, "Nom", 128);
    			
    			// folder_id = primary key
    			DataSourceIntegerField folderIdField = new DataSourceIntegerField(ID_FIELD, "Folder Id");
    			folderIdField.setPrimaryKey(true);
    			folderIdField.setRequired(true);
    			
    			// parent_id = foreign key
    			DataSourceIntegerField folderParentIdField = new DataSourceIntegerField(PARENT_ID_FIELD, "Parent Id");
    			folderParentIdField.setRequired(true);
    			folderParentIdField.setForeignKey(ID_FIELD);
    			folderParentIdField.setRootValue("0");
    			
    			setFields(nameField, folderIdField, folderParentIdField);
    		}
    
    		@Override
    		protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) {
    			int parentId = 0;
    			try {
    				// get the id of node to open. Strangely, can't use getAttributeAsInt, fails for the root id
    				parentId = Integer.parseInt(request.getCriteria().getAttribute(PARENT_ID_FIELD));
    			}
    			catch(RuntimeException e) {
    				GWT.log("Not a number", e);
    			}
    			
    			FilesServiceAsync filesService = FilesServiceAsync.Util.getInstance();
    			filesService.getSubFolders(parentId, new AsyncCallback<Folder[]>() {
    
    				public void onFailure(Throwable arg0) {
    					response.setStatus(RPCResponse.STATUS_FAILURE);
    					processResponse(requestId, response);
    				}
    
    				public void onSuccess(Folder[] folders) {
    					Record[] records = new Record[folders.length];
    					for(int i = 0; i < records.length; i++) {
    						TreeNode treeNode = new TreeNode();
    						Folder folder = folders[i];
    						treeNode.setAttribute(ID_FIELD, folder.getId());
    						treeNode.setAttribute(PARENT_ID_FIELD, folder.getParentId());
    						treeNode.setAttribute(NAME_FIELD, folder.getName());
    						records[i] = treeNode;
    					}
    					response.setData(records);
    					processResponse(requestId, response);
    				}
    			});
    		}
    Please tell me if something is awfully wrong! :)

    Leave a comment:


  • second_comet
    replied
    error bitblaster example

    hi, i able to run bitblaster testadvdatasource.zip example, but on hosted mode, i get some error. pls have a look at screen shot
    Attached Files

    Leave a comment:


  • sjivan
    replied
    Originally posted by CharlesAbetz
    This is possible, all you have to do is remove all references to ListGridRecord in the GWTRPCDataSource and replace it with Record, Also you will need to change the populateRecord implementation to return the Record (and abstract class).
    Yes, this is the right thing to do.

    Leave a comment:


  • CharlesAbetz
    replied
    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!
    This is possible, all you have to do is remove all references to ListGridRecord in the GWTRPCDataSource and replace it with Record, Also you will need to change the populateRecord implementation to return the Record (and abstract class).

    Next thing you have to do is in the populateRecord implementation ie: your data source class, you will need to cast your Record to what ever you want ie: ListGridRecord, TileRecord, TreeRecord, actually anything that implements the Record interface.

    ie:
    TileRecord r = TileRecord.getOrCreateRef(record.getJsObj());
    Hope this helps, anyone trying to do GWTRPCDataSource implementations.

    Please see attached the GWTRPCDataSource file for what to do with getting rid of references to ListGridRecord and changing it to Record.
    Attached Files

    Leave a comment:


  • Isomorphic
    replied
    For the initial fetch, the criteria in dsRequest.data will contain the parentIdField with the rootValue specified on the parentIdField. For subsequent requests, the criteria will be the parentIdField with the ID of whatever node is being opened. See the Tree DataBinding overview.

    Leave a comment:


  • efectobyte@gmail.com
    replied
    fetching TreeGrid

    Helo everyone, I'm trying fetching treegrid on demand but i couldn't.

    How can i distinguish first load of treegrid from other one when user click "plus" to see it childnodes? I've tried printing various getters of request and response... on override method "executeFetch" to see if i can get the diference without success.

    thanks for advance for your help!

    Leave a comment:

Working...
X