Announcement

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

  • rdk
    replied
    Hi,

    Does anyone know how to make gwtrpcdatasource to fetch/update data from a web service which sends json data.

    Here is what I assume we should do. If anyone has other ideas then do let me know :

    1. In the impl file connect to the webservice using some http connector api.
    2. The result is a json string.
    3. Parse the json using some json parsing api and copy in the data beans
    4. Add these to the list and return.

    Isn't this a lot of overhead?

    Leave a comment:


  • sanas
    replied
    benjaminberry,

    First thanks for your share.

    I have a problem with casting Record to ListGridRecord...

    I work with SmartGWT 2.2, Java 1.6 and GWT 2.0.4, but also I tested with SmartGWT2.1 and It's the same...

    This not compile:
    ListGridRecord[] records = response.getData();

    And this...,
    ListGridRecord[] records = (ListGridRecord[]) response.getData();

    ...throws java.lang.ClassCastException: [Lcom.smartgwt.client.data.Record; cannot be cast to [Lcom.smartgwt.client.widgets.grid.ListGridRecord;

    Can you help me? Thank you so much.

    Leave a comment:


  • paatal
    replied
    Urgent ... Can't fetch data

    hi all,
    i tried to use these classes my datagrid is not filling :(
    there is caption "Loading Data" and nothing more.
    what i did wrong ?
    here is my code snippets :
    1.Panel which contains datagrid :
    Code:
    public class RouterTab extends HLayout {
    
    
        private static DataSource dataSource = null;
        private VLayout vLayout = null;
    
        public RouterTab() {
            setHeight100();
            setWidth100();
            setMargin(10);        
            vLayout = new VLayout();
            vLayout.setWidth100();
            vLayout.setHeight100();
            vLayout.setPadding(10);
            addMember(vLayout);
            createDataGrid();
        }
    
        private void createDataGrid() throws IllegalStateException {
            dataSource = RouterDataSource.getInstance();
            final ListGrid listGrid = new ListGrid();
            listGrid.setWidth100();
            listGrid.setHeight100();
            listGrid.setAlternateRecordStyles(true);
            listGrid.setShowAllRecords(true);
            listGrid.setCanResizeFields(true);
            listGrid.setCanReorderFields(true);
            listGrid.setCanSort(true);
            ClientSession.getInstance().getLogger().info("setting datasource RouterDataSource...", null);
            listGrid.setDataSource(dataSource);
            listGrid.setAutoFetchData(true);
            listGrid.setShowFilterEditor(true);
            listGrid.setFilterOnKeypress(true);
            ClientSession.getInstance().getLogger().info("fetching data ...", null);
            listGrid.setAutoFitData(Autofit.BOTH);        
            listGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                    GWT.log("clicked on record", null);
                }
            });
            GWT.log(RouterDataSource.getInstance().getTitle(), null);
            vLayout.addMember(listGrid);
            listGrid.fetchData();
        }
    }
    2. datasource :
    Code:
    public class RouterDataSource extends GwtRpcDataSource<GWTMgtNetRouter> {
    
        public static String DATA_SOURCE_ID = "RouterDataSourceDS";
        private static RouterDataSource instance = null;
    
        public static RouterDataSource getInstance() {
            if (instance == null) {
                instance = new RouterDataSource();
            }
    
            return instance;
        }
    
        public RouterDataSource() {
            super();
            //setID(dataSourceId);
    
            setFetchEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() {
    
                @Override
                public void callEndpoint(AsyncCallback callback, Object... parameters) {
                    ClientSession.getInstance().getLogger().info("event", null);
                    MgtNetServiceAsync mgtNetService = ClientSession.getInstance().getMgtNetService();
                    GWTUserContext context = ClientSession.getInstance().getGWTUserContext();
                    mgtNetService.getMgtNetRouters(context, callback);
                }
            });
            setUpdateEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() {
    
                @Override
                public void callEndpoint(AsyncCallback callback, Object... parameters) {
                    MgtNetServiceAsync stockService = GWT.create(MgtNetService.class);
                    ListGridRecord record = (ListGridRecord) parameters[0];
                // edit
                //stockService.editStock(record.getAttributeAsInt("id"), record.getAttribute("symbol"), callback);
                }
            });
    
            setRemoveEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() {
    
                @Override
                public void callEndpoint(AsyncCallback callback, Object... parameters) {
                    MgtNetServiceAsync stockService = GWT.create(MgtNetService.class);
    
                    ListGridRecord record = (ListGridRecord) parameters[0];
                // remove
                //stockService.removeStock(record.getAttributeAsInt("id"), callback);
                }
            });
    
            setAddEndpoint(new GwtRpcDataSourceEndpoint<GWTMgtNetRouter>() {
    
                @Override
                public void callEndpoint(AsyncCallback callback, Object... parameters) {
                    MgtNetServiceAsync stockService = GWT.create(MgtNetService.class);
                    ListGridRecord record = (ListGridRecord) parameters[0];
                // add
                //stockService.addStock(record.getAttribute("symbol"), callback);
                }
            });
    
            DataSourceIntegerField idDataField = new DataSourceIntegerField("id", "ID");
            idDataField.setPrimaryKey(true);
            DataSourceTextField nameDataField = new DataSourceTextField("name", "Router Name");
            nameDataField.setCanEdit(false);
            DataSourceTextField ipAddressDataField = new DataSourceTextField("ipadress", "IP Adress");
            ipAddressDataField.setCanEdit(false);
            DataSourceDateField regDateDataField = new DataSourceDateField("regdate", "Register Date");
            regDateDataField.setCanEdit(false);
            DataSourceDateField updDateDataField = new DataSourceDateField("upddate", "Update Date");
            updDateDataField.setCanEdit(false);
    
            setFields(idDataField, nameDataField, ipAddressDataField, regDateDataField, updDateDataField);
        }
    
        @Override
        protected void populateRecord(ListGridRecord record, GWTMgtNetRouter gWTMgtNetRouter) {
            record.setAttribute("id", gWTMgtNetRouter.getId().intValue());
            record.setAttribute("name", gWTMgtNetRouter.getName());
            record.setAttribute("ipadress", gWTMgtNetRouter.getIpAddress());
            record.setAttribute("regdate", gWTMgtNetRouter.getRegDate());
            record.setAttribute("upddate", gWTMgtNetRouter.getUpdDate());
        }
    }

    what i did incorrect ?
    setFetchEndpoint is not invoked .....



    ___________________
    Regards,
    Paata Lominadze.
    Magticom LTD.

    Leave a comment:


  • mihai007
    replied
    Well sometimes I also get this feeling of hidden api's but then I think... well they are at beta2, what do you want... give it a little time to sort things up. Actually my implementation of the rpc is worse than this one here and the other new one discovered so...

    Leave a comment:


  • Isomorphic
    replied
    Hi Benjamin,

    Sorry you ended up frustrated, but, realize this is just a matter of timing. We needed to add features to SmartClient to address GWT-RPC integration. Until those features were added, your approach was the right one, the best that could be achieved in the absence of the new features. That's why we stickied the thread and recommended it.

    Alius discovered the new features in not-quite-final form while we were still working on examples, and in particular trying to figure out a way around the somewhat awkward need to copyValues() as shown in Alius' example. Just normal development cycle stuff, not secret APIs.

    In retrospect, copyValues() is not so bad, just imperfect, and we probably should have just posted a sample with a similar approach, since the new APIs do enable paging.

    As far as SmartGWT EE, we're not trying to be secretive about that either, as we've touched on elsewhere it basically allows integration with the SmartClient Server. The DMI feature gives you the ability to do something similar to GWT-RPC, but with no need for a special RemoteService class or any other extra classes involved. Values are populated into your Java beans via reflection, with automatic validation, as well as the ability to compose together a series of calls as a single HTTP request via queuing. If you want more details, there's an example here where both the XML DataSource format and server-side code involved are identical in SmartGWT EE.

    Leave a comment:


  • sjivan
    replied
    Hi Benjamin,
    I had responded to your earlier post here saying :

    I understand the issue you're running into and although do-able, it's not super convenient integrating gwt-rpc due to the points you raise. A couple of key API's have been incorporated into SmartClient to support getting gwt-rpc integration to be smoother. I will have to validate and then incorporate them.

    You could proceed the path you're taking and update the code when the feature is incorporated. This is a priority along with other features like i18n and exposing the ResultSet API. So "star" the issue in tracker if it is important to you.
    The issue tracker has a voting system which is considered when priotitizing tasks. i18n is on the top of the list and support for it has just been added. Adding the ResultSet API also has a lot of votes and is equally important.

    Please rest assured that there are no hiding games being played here. Why else would the custom datasource feature be added to SmartClient. It was added specifically to support GWT-RPC and you'll notice that earlier builds / releases of SC didn't have this feature. It takes some time to validate and test such a solution before pushing it out and alius got there first.

    Yes, there are still some API gaps between SmartClient and SmartGWT and if you discover an API you need which is missing, file an issue. Or if a particular feature is important to you, make sure there is a feature request in tracker for it, and that you "star" it.

    Sanjiv

    Leave a comment:


  • benjaminberry
    replied
    It's a bit frustrating that this is what you had in mind and when I had asked explicitly how users should tackle this problem you previously pointed at overloading transformRequest in the fashion I did.

    If alius does not go searching through your source then we'd all be stuck with an inferior approach to this problem. But now that he has this is the new standard. This makes me wonder if there aren't other enhancements to this approach that haven't been made public yet.

    You have not clearly communicated to the community what SmartGWT EE is going to do, only that it's coming and that the hardest problems people are trying to solve right now with your product may go away with it. In the mean time you seem content to let users fumble around the dark about how you want them to uses datasources and gwt-rpc. This is not productive for your end users.

    Benjamin

    Leave a comment:


  • Isomorphic
    replied
    Ben, thanks again for posting this example, which has helped a number of users, and thanks everyone else for the various refinements. However the approach shown by Alius in this thread uses some new SmartClient APIs to provide a cleaner integration approach that is able to support paging and has a few other advantages - please take a look.

    Leave a comment:


  • alius
    replied
    Another implementation.

    Hi,

    Just posted another GWT-RPC implementation with working RPC service example.
    http://forums.smartclient.com/showthread.php?t=4814


    Aleksandras

    Leave a comment:


  • [RTS]BN+VS*
    replied
    Originally posted by ben75000
    Do you plan an intergration of a RPC datasource in smartGWT ?
    Yeah, I think a standard way for doing this would be appreciated :)

    Leave a comment:


  • ben75000
    replied
    Do you plan an intergration of a RPC datasource in smartGWT ?

    Leave a comment:


  • jasonzhang2002
    replied
    supported Tree over GWT-RPC

    Hi, I modified GwtRpcDataSource to support Tree load on demand over GWT-RPC.
    I only tested Fetch right now.
    The method I modified is executeFetch
    Code:
    protected void executeFetch(final DSRequest request)
    	{
    
    		fetchEndpoint.callEndpoint(new AsyncCallback<Object>()
    		{
    
    			public void onFailure(Throwable caught)
    			{
    				fetchEndpoint.postFailure(caught);
    			}
    
    			public void onSuccess(Object object)
    			{
    				Collection<T> resultSet = fetchEndpoint.transformResult(object);
    				 JavaScriptObject obj=request.getAttributeAsJavaScriptObject("parentNode");
    			  	 TreeNode parentNode=new TreeNode(obj);
    			  	 TreeNode[] nodes=new TreeNode[resultSet.size()];
    			  	 
    			  	 
    			  	 int index=0;
    				for (T result: resultSet)
    				{
    					
    					DSRequest req = new DSRequest();
    					req.setAttribute(DO_NOT_HANDLE, true);
    
    					final TreeNode node = new TreeNode();
    					populateRecord(node, result, request);
    					nodes[index++]=node;
    				}
    				//http://forums.smartclient.com/showthread.php?t=173&highlight=client+tree
    				// You have to pass somehow the Tree into DataSource. It is not good to make
    				//DataSource depend on Tree. But this is the only way I can make it work.
    				tree.addList(nodes, parentNode);
    				// This approach does not work
    				//parentNode.setChildren(nodes);
    
    				fetchEndpoint.postSuccess(object);
    			}
    		}, request, parameters);
    	}
    My populateRecord is different
    Code:
    	protected abstract void populateRecord(ListGridRecord record, T object, DSRequest request);
    An example popupateRecord implementation
    Code:
    protected void populateRecord(ListGridRecord record, Node node, DSRequest request)
    	{
    		record.setAttribute("name", node.getName());
    		 JavaScriptObject obj=request.getAttributeAsJavaScriptObject("parentNode");
    	  	 TreeNode parentNode=new TreeNode(obj);
    	  	
    		//need to set id based on request
    		record.setAttribute("id", parentNode.getAttribute("id")+"."+node.getName());
    		record.setAttribute("folder", true);
    	}

    Leave a comment:


  • Przemeq
    replied
    Hi, I've made 1 change to enable server pagination to your code:

    Code:
       public GwtRpcDataSource() {
          //setClientOnly(true);
       }
    and now I get this error (in attachment)

    does it means that I can't use server side data pagination with rpc in free (lgpl) version?

    more source files in attachments
    Attached Files
    Last edited by Przemeq; 18th Mar 2009, 11:28.

    Leave a comment:


  • sjivan
    replied
    com.smartgwt.extensions sounds good.

    Benjamin, send me an email (sanjiv dot jivan at gmail) with your google ID. I'll add you as a commiter.

    Thanks,
    Sanjiv

    Leave a comment:


  • nlotz
    replied
    Originally posted by benjaminberry
    That makes sense, how can I get this code into extensions?
    Sanjiv will add you as a developer of smartgwt-extensions and after that you should be able to commit to SVN.

    I will populate the project with a Maven build specification in the next few days and add your code if you haven't done so, already.

    @Sanjiv: Do you have a name for the root package of all extensions in mind ? Something like com.smartgwt.ext or com.smartgwt.extensions ?

    In the latter case your code would end up in
    [...]/trunk/main/src/com/smartgwt/extensions/gwtrpc/GwtRpcDataSource.java
    or something similar.

    P.S.: I would vote for extensions instead of ext to avoid confusion with other libraries.

    Leave a comment:

Working...
X