Announcement

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

    SmartGWT and Restlet

    Hi, i'm newbie in smartgwt..
    i have some problem to consume json from web service. First of all i have two projects. Web Service using Restlet and SmartGWT LGPL version, my problem is I want to consume json from restlet for my client side(smartgwt).
    Here is my code :

    Code:
    package com.berca.ahu.fidusia.client.ui.data;
    
    import org.restlet.gwt.Client;
    import org.restlet.gwt.data.Protocol;
    
    import com.smartgwt.client.data.OperationBinding;
    import com.smartgwt.client.data.XJSONDataSource;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DSOperationType;
    import com.smartgwt.client.types.DSProtocol;
    import com.smartgwt.client.types.RPCTransport;
    
    public class DSUser extends XJSONDataSource{
    	
    	private static DSUser instance = null;  
    	final Client client = new Client(Protocol.HTTP);
    	final String URL ="http://localhost:8080/AHUFidusiaWebservice/users/1";
        
    	public static DSUser getInstance() {  
            if (instance == null) {  
              instance = new DSUser("DSUser_JSON");  
            }  
            return instance;  
        }  
    
       
        public DSUser(String title) {  
        
        	setDataProtocol(DSProtocol.POSTPARAMS);
        	setDataFormat(DSDataFormat.JSON);
        	DataSourceTextField name = new DataSourceTextField("username", "Username");
        	name.setValueXPath("username");
        	DataSourceIntegerField id = new DataSourceIntegerField("id", "Id");
        	id.setValueXPath("id");
        	id.setPrimaryKey(true);
        	setDataURL(URL);
        	OperationBinding fetch = new OperationBinding();  
        	fetch.setOperationType(DSOperationType.FETCH);  
        	fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
        	setRecordXPath("/users");
        	setDataTransport(RPCTransport.SCRIPTINCLUDE);
        	setCallbackParam("callback");
        	setFields(id, name);
        }
    }
    Anybody help?
    Thanks

    #2
    I have a similiar project with vanriana. I get an error message when making a request json data to the webservice.
    This is the error message:
    Uncaught JavaScript exception [Script error.] in , line 0

    Comment


      #3
      anybody have an idea please?

      Comment


        #4
        Make the URL relative or it is considered a cross-domain call.

        If you need further help, post all the information listed in the FAQ.

        Comment


          #5
          and how to solve it?

          Originally posted by Isomorphic
          Make the URL relative or it is considered a cross-domain call.

          If you need further help, post all the information listed in the FAQ.

          Comment


            #6
            hi, i get message in restlet console, there was an request to service..
            but i can't get data show in my Listgrid. sorry i'm new in smartgwt and restlet..

            here is message :

            Jul 13, 2011 9:33:02 AM org.restlet.engine.log.LogFilter afterHandle
            INFO: 2011-07-13 09:33:02 0:0:0:0:0:0:0:1 0.0.0.0 8080 GET /AHUFidusiaWebservice/users/1 _operationType=fetch&_startRow=0&_endRow=75&_textMatchStyle=substring&_componentId=isc_ListGrid_1&_dataSource=isc_UserView_1_0&isc_metaDataPrefix=_&isc_dataFormat=json&callback=isc.Comm._scriptIncludeReply_0 200 - - 16 http://localhost:8080 Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0 http://127.0.0.1:8888/Fidusia.html?g...127.0.0.1:9997


            and this still the same in gwt console

            Uncaught JavaScript exception [Script error.] in , line 0
            Code:
            public class DSUser extends RestDataSource{
            	
            	private static DSUser instance = null;  
            	final Client client = new Client(Protocol.HTTP);
            	final String URL ="http://localhost:8080/AHUFidusiaWebservice/users/1";
                
            	public static DSUser getInstance() {  
                    if (instance == null) {  
                      instance = new DSUser("DSUser_JSON");  
                    }  
                    return instance;  
                }  
            
             setDataFormat(DSDataFormat.JSON);
                    setDataProtocol(DSProtocol.GETPARAMS);
                    this.setDataTransport(RPCTransport.SCRIPTINCLUDE);
                    this.setDataURL(URL);
                    this.setJsonRecordXPath("/users");
                    
                	DataSourceTextField name = new DataSourceTextField("username", "Username");
                	name.setValueXPath("username");
                	DataSourceIntegerField id = new DataSourceIntegerField("id", "Id");
                	id.setValueXPath("id");
                	id.setPrimaryKey(true);
                    setFields(id, name);
                }
            }
            thanks.
            Last edited by vanriana; 12 Jul 2011, 18:41.

            Comment


              #7
              Originally posted by Isomorphic
              Make the URL relative or it is considered a cross-domain call.

              If you need further help, post all the information listed in the FAQ.
              Thanks.. But, how to solve cross-domain call?

              Comment


                #8
                this is a relative url: /somedir/somefile.html
                this is an absolute url: http://someserver.com/somedir/somefile.html

                Comment


                  #9
                  Originally posted by atomatom
                  this is a relative url: /somedir/somefile.html
                  this is an absolute url: http://someserver.com/somedir/somefile.html

                  Hi atomatom,
                  My project is running in two ports..

                  localhost:8888 for smartgwt

                  and

                  localhost:8080 for web service (Restlet)

                  and how i make these projects communicate in json?
                  ho i solve this problem, can you help me? Would you like give me example..
                  i really thanks for your help..

                  thanks
                  Last edited by vanriana; 13 Jul 2011, 18:52.

                  Comment


                    #10
                    some people help me please ...............................

                    Comment


                      #11
                      Originally posted by vanriana
                      Hi atomatom,
                      My project is running in two ports..

                      localhost:8888 for smartgwt

                      and

                      localhost:8080 for web service (Restlet)

                      and how i make these projects communicate in json?
                      ho i solve this problem, can you help me? Would you like give me example..
                      i really thanks for your help..

                      thanks
                      I'm still get error..

                      Comment


                        #12
                        i'm still haven't solution for this problem..
                        anyone have idea?

                        Comment


                          #13
                          Originally posted by vanriana
                          i'm still haven't solution for this problem..
                          anyone have idea?
                          Are you sure you need XJSonDataSource? I've never used it, since if you don't really do cross-domain calls then RestDataSource is just enough (it really rocks... I've never had problems with it).

                          By the way, I suppose you have to post:
                          1. the SmartGWT or SmartClient version and browser version(s) involved;

                          2. for a server-side problem, the complete logs generated during processing of the request;

                          3. for a client-side problem, the contents of the Developer Console (see FAQ for usage);

                          4. if there is a JavaScript error, the stack trace logged in the Developer Console (from Internet Explorer if possible); and

                          5. sample code.

                          Posts with incomplete information are much more likely to be ignored.
                          if you want Isomorphic helps you (as he told you).

                          Cheers
                          Davide

                          Comment


                            #14
                            Originally posted by d.cavestro
                            Are you sure you need XJSonDataSource? I've never used it, since if you don't really do cross-domain calls then RestDataSource is just enough (it really rocks... I've never had problems with it).

                            By the way, I suppose you have to post:

                            if you want Isomorphic helps you (as he told you).

                            Cheers
                            Davide
                            Hi Davide..
                            thanks for reply.
                            I had try with RestDatasource like this post click
                            but it still get error, and i had also try with relative path, it also still error like looping forever.
                            i use smartgwt 2.4, browser firefox 5
                            Can you give some example for me, how to be smartgwt and restlet are communicate.
                            sorry davide, i'm really newbie with this problem..

                            thanks in advance

                            Comment


                              #15
                              Personnaly I don't know, but found this with google and I think it could help you.
                              Let us know;

                              Alain

                              Comment

                              Working...
                              X