Announcement

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

    Hi,

    This is crazy topic about Gwt RPC !

    From what I read, almost everything has been writen except for one point about which I'd like to get community feedback.

    How do you manage DTOs (or Entities) having relationship with "complex" objects ?

    I mean, imagine a simple tree structure :

    Code:
    class Person {
      private Integer id;
      private String name;
      private Person boss;
    }
    For the mapping, I will certainly do something like :

    Code:
    	DataSourceField field;
    
    	field = new DataSourceIntegerField("id");
    	field.setPrimaryKey(true);
    	field.setRequired(false);
    	field.setCanEdit(false);
    	addField(field);
    
    	field = new DataSourceTextField("name");
    	field.setRequired(true);
    	addField(field);
    
    	field = new DataSourceIntegerField("boss");
    	field.setRequired(false);
    	field.setForeignKey("id");
    	addField(field);
    When fetching records, I will be able to extract the foreign key using
    Code:
    setAttribute("boss",entity.getBoss().getId());
    and I'll be able to create new Record s without trouble.

    My concern is about rebuilding the entity on add/update requests since I'll only be given the id and Person.setBoss(Person p) wants a Person, not an Integer ... Even worst, if I imagine trying to retrieve a Person record/object using the id (DataSource.fetchData()), this is done asynchronously which is not acceptable.

    I'd be happy to read about your options ...

    Comment


      Originally posted by BeezeR
      Thanks, but i have problem with update my results after fetch with criteria. My service sends result, but after processResponse(requestId, response); doesn`t update UI. Next action after that is execute fetch without criteria. Do you have these problem?
      maybe this is your problem...
      Originally posted by jzaruba
      When implementing REMOVE (or any non read-only operation) do not forget to mark exactly one of your DataSourceFields as primaryKey.
      Without that your DSResponse.getData() will return empty array.

      Comment


        Hi mnenchev

        Originally Posted by mnenchev
        Download from here :http://rapidshare.com/files/28695615...ample.zip.html
        Can you upload this file again?

        Many Thanks
        Last edited by rfa; 23 Oct 2009, 01:13.

        Comment


          Originally posted by kassec
          Hi,

          This is crazy topic about Gwt RPC !

          From what I read, almost everything has been writen except for one point about which I'd like to get community feedback.

          ...

          When fetching records, I will be able to extract the foreign key using
          Code:
          setAttribute("boss",entity.getBoss().getId());
          and I'll be able to create new Record s without trouble.

          I'd be happy to read about your options ...
          I'm not sure how this could possibly work without sending all the data (person, its boss, his boss, his boss, etc... whole db?) in one request. Otherwise your getBoss() call (which IMO happens on the client side) would either always return null OR it would have to make another (synchronous!) request to fetch the boss entity from the server.

          My understanding is that lazy many-to-one relations do not cope with the GWT concept.
          (I would be happy should anyone correct me on this.)
          Last edited by jzaruba; 28 Oct 2009, 14:04.

          Comment


            UPDATE: transformRequest and processResponse seem to be the cure :)

            Has anyone made TreeGrid working with both primaryKey and foreignKey being Integer-fields?

            Code:
            DataSourceIntegerField employeeIdField = new DataSourceIntegerField("id", "Employee");
            employeeIdField.setPrimaryKey(true);
            
            DataSourceIntegerField bossIdField = new DataSourceIntegerField("bossId", "Reports to");
            bossIdField.setForeignKey("id");
            
            DataSourceTextField nameField = new DataSourceTextField("name", "Name");
            
            ...
            
            Record record = new ListGridRecord();
            // note data types of the attributes
            record.setAttribute("id", id); // Integer
            record.setAttribute("bossId", bossId); // Integer
            record.setAttribute("name", name); // String
            It seems to me that such Record simply does not work with the target treeGrid when being added from within transformResponse method, when added let's say from the DataSource constructor everything works fine...
            To get the record in the treeGrid via transformResponse I have to set its bossId attribut as a string instead of int, which creates complications elsewhere. (Because in db the 'bossId' field is obviously of the same type as the primary key 'id', both of them are Integers.)

            What is the proper pray of populating TreeGrid with data frmo GWT-RPC?
            Last edited by jzaruba; 28 Oct 2009, 17:49.

            Comment


              Another pitfall with TreeGrid: Avoid using null as rootValue for foreignKey dataSourceField.
              Even though null is the default rootValue when you don't set it otherwise via myForeignKeyField.setRootValue it does not work with add-operation. (No problem with update or fetch.)

              Just set rootValue to 0 and translate zeroes back to nulls before saving the record.
              Last edited by jzaruba; 4 Nov 2009, 23:55.

              Comment


                SmartGWT Record[] ListGrid (and more?) bug...

                Originally posted by sjivan
                Hi Aleksandras,
                You're right, I'll change the API's to accept Record.

                Sanjiv
                Using SmartGWT 1.3:

                Code:
                Record[] list = new Record[result.getFetchedList().size()];
                for (int i = 0; i < list.length; i++)
                {
                	Record record = new Record();
                	copyValues(result.getFetchedList().get(i), record);
                	list[i] = record;
                }
                response.setData(list);
                The above code compiles, however it still does not work completely. Using for example a ListGrid object that is bound to the DataSource, the following error will be seen:

                Code:
                Uncaught JavaScript exception [java.lang.ClassCastException: com.smartgwt.client.data.Record cannot be cast to com.smartgwt.client.widgets.grid.ListGridRecord
                 at com.smartgwt.client.widgets.grid.ListGridRecord.getOrCreateRef(ListGridRecord.java:91)
                I'm assuming that based on previous posts here that Record[] should indeed be a valid type for all DataBound components, so this is probably a bug in SmartGWT.

                I have not tested the other data bound components, it is possible this is the only one this happens with, but if this is part of a bug fix then I recommend checking the others as well.

                Comment


                  Originally posted by noone123
                  Using SmartGWT 1.3:

                  I'm assuming that based on previous posts here that Record[] should indeed be a valid type for all DataBound components, so this is probably a bug in SmartGWT.
                  Different UI components works with different kinds of records (ListGridRecord, TreeGridRecord etc.) and you have to provide correct record instance for specific UI component.

                  Here is your corrected code:
                  Code:
                  Record[] list = new Record[result.getFetchedList().size()];
                  for (int i = 0; i < list.length; i++)
                  {
                  	Record record = new ListGridRecord();
                  //                                     ^^^^^^^^^^^^^^^
                  	copyValues(result.getFetchedList().get(i), record);
                  	list[i] = record;
                  }
                  response.setData(list);
                  It is not a bug. Record is just parent for all record implementations (maybe it should be abstract?).
                  If you want to have generic DS then you have to check calling component and based on it instantiate correct record implementation.

                  Alius

                  Comment


                    Hi Alius,
                    The idea is that all DataBound components should actually work with the generic Record type. Users can use widget specific record types but they should be interchangeably be able to used to display contents of other DataBound components. So the GwtRpcDataSource should really only be working at the "Record" level so that it can be used with any DataBoundComponent.

                    Sanjiv

                    Comment


                      Hi everyone, after spending a couple of hours wrapping my head around everything I've made a small example using GwtRpcDataSource.

                      All it does is populate ComboBoxItems by:

                      1) Passing the data plain as a String[][] using GWT-RPC and building the DataSource at the client side. (I saw this approach made in a document by Sanjiv about migrating to SmartGWT)

                      2) Extending GwtRpcDataSource and implementing the fetch method.

                      Here it is

                      Its an Eclipse project which has the Google Plugin for Eclipse installed. The SmartGWT jar needs to be added to the build path.

                      I made it simple enough for me to learn from, so I hope it helps another newbie like me out there!

                      Comment


                        Issue

                        Originally posted by nabla52
                        Hi

                        Isomorphic told me to post my query in this thread, so here it:

                        When a validation error occurs from my (GWT) server, I do the following (as an example):

                        <code>
                        final Map<String, String> fieldErrors = new HashMap<String, String>();
                        fieldErrors.put("name", "This should be my error message");
                        final DSResponse response = new DSResponse();
                        response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
                        response.setStatus(DSResponse.STATUS_VALIDATION_ERROR);
                        response.setErrors(fieldErrors);
                        processResponse(request.getRequestId(), response);
                        </code>

                        This works with a DynamicForm i.e. the field "name" gets an error icon and you can hover over it and the message is shown. However when using a ListGrid the error message shown against the column (named 'name' and which gets an error icon) is always "undefined" !!! Why? If I explicitely use ListGrid.setFieldError(row, "name", "This should be my error message") the ListGrid displays the right message! It seems that DSResponse does not hand back the error message to the ListGrid (but it does to the DynamicForm)!

                        Can you help. Many thanks
                        Hi nabla52,

                        Did you create an issue for this?
                        I have the same problem using a ListGrid.

                        The workaround you provided works but it would be nice if the method
                        DSResponse.setErrors(Map errors) also works with a ListGrid.

                        Thanks.

                        Comment


                          DataSource and DatasourceField

                          Hi,

                          I try to create GWT-RPC DataSource and i want to define the DatasourceField
                          after the first "AsyncCallback fetch", (from sql meta values) :
                          DataSourceTextField(ColumnName , ColumnLabel)

                          but i get error message :
                          Code:
                          Fields cannot be added to a DataSource after the underlying component
                          has been created
                          I understand this message but i need help for a implementation

                          Thanks

                          Regis

                          Comment


                            Question regarding paging

                            Hi:

                            I am trying to understand how paging is supposed to work in a ListGrid using TestAdvDataSource.zip code. I have the following simple issue that I am not able to resolve.

                            My table in the database has 110 records and I do not want to fetch all of them at once into the ListGrid. I suppose using the pattern in TestAdvDataSource code base will enable the ListGrid to fetch in batches, say 60 at a time as one scrolls through the grid.

                            I have made server side code to take the start and end row parameters and therefore I get only 60 records at a time. However, what I am seeing is that in the onSuccess method of the DataSource object a new rpc call is fired to the server right after the processResponse(requestId, response) line of the code when the first batch of records are fetched. As a result, the second rpc call brings back the remaining 50 records from the database and overlaying the data in the grid with the 50 records.

                            However, I am under the impression that the second batch of the records will not be fetched by the listGrid until you scroll down. Is my understanding right? If so, could you please let me know what I might be doing wrong?

                            Your help is greatly appreciated.

                            Thanks
                            Ram

                            Code:
                            @Override
                            public void onSuccess(FetchResult<DataRecord> dataRecordSet)
                            {
                               response.setData(dataRecordSet.getFetchedList());
                               response.setStartRow(dataRecordSet.getStartRow());
                               response.setEndRow(dataRecordSet.getEndRow());
                               response.setTotalRows(dataRecordSet.getTotalRows());
                               processResponse(requestId, response);
                            }
                            Last edited by tullurir; 1 Dec 2009, 06:57.

                            Comment


                              GWT-RPC DataSource sample

                              Hi Alexandras/Isomorphic,

                              I was following through your post
                              http://forums.smartclient.com/showthread.php?t=4814

                              and if I'm not mistaken, I tried pouring over the SmartGWT 2.0 jars and it seems that the required changes have already been included.

                              As I'm new to this, could I ask you for complete sample codes on the usage of the GWT-RPC DataSource?

                              Thanks!

                              Comment


                                Have a look at post #205, and see if it helps you :)

                                Originally posted by junieboy
                                Hi Alexandras/Isomorphic,

                                I was following through your post
                                http://forums.smartclient.com/showthread.php?t=4814

                                and if I'm not mistaken, I tried pouring over the SmartGWT 2.0 jars and it seems that the required changes have already been included.

                                As I'm new to this, could I ask you for complete sample codes on the usage of the GWT-RPC DataSource?

                                Thanks!

                                Comment

                                Working...
                                X