Announcement

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

    #31
    Hi Marbot,

    Thanks for the sample working project, I am new to SmartGWT and tring to evaluate if I can start using it for my projects. I have a question , Do I have to create the client side stub (interface) for the RPC service plus Async class for each DataObject I have ? So if I have 30 DatabObjects then there will be at 30 client side Interfaces plus corresponding Async ?
    What about the server side ?

    thanks,
    Originally posted by marbot
    And here's a .zip containing the whole working test project (you'll need to compile it once to get your /sc -folder with the skins and icons):

    http://www.marbot.org/ListGridTest.zip
    (btw, why can't we upload .zip's?)

    It shows a ListGrid making server-side paging and sorting using the GenericGwtRpcDataSource showed below, as well as adding and removing rows. Double-click a row to edit it. Example sources are attached.

    cheers
    marbot

    Comment


      #32
      Originally posted by tz_dev
      Hi Marbot,

      Thanks for the sample working project, I am new to SmartGWT and tring to evaluate if I can start using it for my projects. I have a question , Do I have to create the client side stub (interface) for the RPC service plus Async class for each DataObject I have ? So if I have 30 DatabObjects then there will be at 30 client side Interfaces plus corresponding Async ?
      What about the server side ?

      thanks,
      Hi

      Correct, with the actual GenericGwtRpcDataSource Version, you'll have to create client side service stubs as well as a server-side implementation for each DataObject / DataSource you have. The problem here is that GWT needs to "compile" the Java code in Javascript at compile time: that's why the GWT.create() method requests a .class literal, and won't work when defining the class at runtime (using .getClass()). GenericGwtRpcDataSource uses Generics, which are type-erased at java-compiletime, and therefore makes it impossible to get their .class-literals.

      Please note that GenericGwtRpcDataSource is only a helper for small, say "hobby"-projects. It hasn't any kind of professional support, nor is it optimized for performance or security. Anyone using SmartGWT professionally should strongly think about using the SmartGWT EE Edition - as I'm planning to do myself.

      The SmartGWT EE Edition allows to define DataSources without defining any service-stubs or server-code at all - I think you should have a look at it when evaluating SmartGWT. I personally think SmartGWT (EE) is one of the best web-frameworks out there.

      cheers
      marbot

      Comment


        #33
        Hi marbot,

        the generic datasource works very well, thanks again for that!
        the problem i have is may be off topic, anyway

        i use a ListGrid, and a button to add new rows: listGrid.addData(rec);

        the record is actually empty, and my backend unfortunatelly has to save this empty record, even though the data integrity is broken
        than after editing the "update" method is called, and every thing is fine

        how can i avoid saving the invalid empty record?
        is there a way to validate the record before the "add" method on the datasource?

        regards
        andre

        Comment


          #34
          Originally posted by a.reiter
          i use a ListGrid, and a button to add new rows: listGrid.addData(rec);

          the record is actually empty, and my backend unfortunatelly has to save this empty record, even though the data integrity is broken
          than after editing the "update" method is called, and every thing is fine

          how can i avoid saving the invalid empty record?
          is there a way to validate the record before the "add" method on the datasource?
          Hi andre

          Well, looking at the JavaDoc of the addData(Record record)-Method, it does just that: "Perform a DataSource "add" operation to add new records to this component's DataSource.". I suppose there're different options here:

          a) use a form with separate fields, validate the form and add the data to the list if the validation is correct. There're a few examples on the showcase for form validation.

          b) make sure the initialization of your ListGridRecord is complete and DI is valid before you call listGrid.addData(rec). ...maybe you'll have to get the correct id's from the server beforehand.

          c) simply skip the insert server-side... i don't know how the ListGrid will react, though. IMHO a dirty fix.

          I've gone through the ListGrid methods, and I don't see a way to add a record without calling the datasource "add"... but maybe I've overseen something.

          ...and you're right: the problem is of topic! :-) But I'm glad to hear that the generic gwt rpc datasource works well.

          cheers
          marbot

          Comment


            #35
            Hi marbot,

            Originally posted by marbot
            And here's a .zip containing the whole working test project (you'll need to compile it once to get your /sc -folder with the skins and icons):

            http://www.marbot.org/ListGridTest.zip
            (btw, why can't we upload .zip's?)

            It shows a ListGrid making server-side paging and sorting using the GenericGwtRpcDataSource showed below, as well as adding and removing rows. Double-click a row to edit it. Example sources are attached.

            cheers
            marbot
            I have downloaded the ListGridTest.zip file and was able to integrate with my application, I have the following questions

            a) How will ensure that the same results are not returns to different client calls, is a single datasource shared across different client calls or do we instantiate new datasource for each browser client ?

            b) In the YourServiceImpl.java when do we need to load the item list, will the items list be refreshed in every fetchData() call ?

            Thanks for uploading the test sample application.

            Comment


              #36
              Originally posted by gwtuser123
              Hi marbot,

              I have downloaded the ListGridTest.zip file and was able to integrate with my application, I have the following questions

              a) How will ensure that the same results are not returns to different client calls, is a single datasource shared across different client calls or do we instantiate new datasource for each browser client ?

              b) In the YourServiceImpl.java when do we need to load the item list, will the items list be refreshed in every fetchData() call ?

              Thanks for uploading the test sample application.
              Hi

              I'm not sure I understand your questions.

              a) The DataSource is client code, and therefore get instantiated for each client. The server implementation is - of course - instantiated once, and the data is the same for all clients.

              b) No, the item list will not be refreshed, because it is static and therefore only get instantiated once. Please note that my sample project is only an example - a "real" server-implementation would most probably use a database to persist the data, and not a static List.

              Anyway, it's raining again in Switzerland, so I enhanced the example with filtering. I also improved the server implementation a bit.

              It can be downloaded here:

              http://www.marbot.org/ListGridTest.zip

              cheers
              marbot

              Comment


                #37
                Hi Marbot,

                Thank you for all your hard work, it is all working perfectly.
                Just a quick question, I am updating my datasource (database) and then want to return the id so that I can use it to update related records I was wondering if there was an easy way to do this using the code you created.

                Thank you,

                j

                Comment


                  #38
                  Hi j

                  Maybe you're looking for something like the following:

                  Code:
                  yourGrid.addEditCompleteHandler(new EditCompleteHandler() {
                  	
                  	@Override
                  	public void onEditComplete(EditCompleteEvent event) {
                  		event.getRowNum();
                  		event.getNewValues();
                  		//event.get...
                  		//yourGrid.refreshRow(...)
                  	}
                  });
                  I have not tested it - maybe it fits your needs...

                  cheers
                  marbot

                  Comment


                    #39
                    How can i be able adapt your RPC code to cater for on demand loading of a treegrid ?

                    Comment


                      #40
                      Thank you very much for your prompt reply.

                      I have been collecting data from a variety of forms which make up one record in my database. What I have been doing (rightly or wrongly) is creating a new ListGridRecord in my datasource object and then adding to it using setAttribute as values are available. When the record is then complete I am calling addData on the datasource and the data is added. It is at this point I would like to get the resulting id if possible??

                      Thanks in advance!
                      Jen
                      Last edited by jrich; 23 Jun 2010, 02:32.

                      Comment


                        #41
                        Originally posted by jrich
                        Thank you very much for your prompt reply.

                        I have been collecting data from a variety of forms which make up one record in my database. What I have been doing (rightly or wrongly) is creating a new ListGridRecord in my datasource object and then adding to it using setAttribute as values are available. When the record is then complete I am calling addData on the datasource and the data is added. It is at this point I would like to get the resulting id if possible??

                        Thanks in advance!
                        Jen
                        Hi Jen

                        Well, this seems simple:

                        Code:
                        IButton addRow = new IButton("Add new row");  
                        addRow.addClickHandler(new ClickHandler() {  
                           public void onClick(ClickEvent event) {  
                                ListGridRecord rec = new ListGridRecord();  
                                rec.setAttribute("name", "yourName");  
                                rec.setAttribute("location", "yourLocation");                   
                                //yourGrid.addData(rec);
                                YourDataSource.getInstance().addData(rec, new DSCallback() {			
                        		@Override
                        		public void execute(DSResponse response, Object rawData, DSRequest request) {
                        			String id = response.getData()[0].getAttribute("id");
                        		}
                        	});
                            }             
                        });
                        Cheers
                        marbot

                        Comment


                          #42
                          Thank you Marbot,

                          As you say, simple! Should have seen it.

                          Regards
                          Jen

                          Comment


                            #43
                            Hi,

                            Following your example I'm trying to make the datasource parametrizable (= allow to pass some argument to it to dynamically modify it). I was trying to modify YourGwtRpcDataSource to make stuff like that :
                            Code:
                            	@Override
                            	public YourServiceAsync getServiceAsync() {
                            		System.out.println("création of YourService.class");
                            		//return new YourService();
                            		
                            		YourServiceAsync ysa = (YourServiceAsync)GWT.create(YourService.class);
                            		ysa.setUserName("test1");
                            
                            		return ysa;
                            	}
                            In order to do that I need to add this method to YourServiceAsync, is'nt it ?
                            However I cannot do that because the compiler says :
                            Code:
                            public interface YourServiceAsync extends GenericGwtRpcDataSourceServiceAsync<YourDataObject> {
                            	void setUserName(String userName);
                            }
                            <<
                            YourServiceAsync is missing method setUserName(String, AsyncCallback<Void>)
                            >>

                            I'm a little stuck there. Have you got any clues for passing argument to YourServiceImpl ?

                            Regards,
                            Denis.

                            Comment


                              #44
                              I found a way to handle that inside YourGwtDataSource which on what I understand is executed on the client side :
                              Code:
                              	@Override
                              	public YourServiceAsync getServiceAsync() {
                              		System.out.println("création of YourService.class");
                              		//return new YourService();
                              		
                              		YourServiceAsync ysa = (YourServiceAsync)GWT.create(YourService.class);	
                              		 AsyncCallback<String> callback = new AsyncCallback<String>() {
                              		      public void onFailure(Throwable caught) {
                              		        Window.alert(caught.toString());
                              		      }
                              
                              		      public void onSuccess(String result) {
                              		    	  
                              		      }
                              		 };
                              		
                              		ysa.setUserName("test", callback);
                              		//ysa.password="test";
                              		//ysa.uri="http://localhost:6060/test-api/View/1";
                              		return ysa;
                              	}

                              Comment


                                #45
                                Hello,

                                The fetch method of the service I'm implementing might throws various exceptions. However, the YourServiceImpl implements YourService which extends GenericGwtRpcDataSourceService<YourDataObject>. And the signature of GenericGwtRpcDataSourceService defines a fetch() method whithout any exception so the exception cannot be propagated to client datasource. Do you know a way to be able to throw exception with the fetch method ?

                                Regards,
                                Denis.

                                Comment

                                Working...
                                X