Announcement

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

    Best practice question re. sending multiple listgrid records to server

    Hi, just hoping for some input regarding a thing i'm about to start with.

    -I have a "users" datasource, that i use in listgrids for Showing, Create, update, delete operations. Works fine.

    -I now have a case where i want to show all users in a similar listgrid, but have the ability to select them with a checkbox and when a button is pressed, send the ID's of the selected records to a spring service method i have on the server.


    I can think of several ways - code a custom RPC server method that i call from my button clicklistener, or a custom "update" method somehow, setting the operationid when the button is clicked, then call savedata.


    I really only want the id's to be sent to the server, preferrably in one single server call. What would you say is the best approach?

    Would be great with some thoughts.

    #2
    Best practice is to use a CRUD operation if what you are doing is a CRUD operation. For example, if what this operation does is return a list of matching records, use a "fetch" operation and send the list of IDs in the criteria.

    Comment


      #3
      Hey Iso, thanks for responding.

      Yeah, perhaps i wasn't clear. To *popuplate* the grid, i use an autofetchdata-listgrid.

      My question was about what i do when i have datasource-data, but i have other uses *besides* a crud operation.

      In this case, fetch the data first, then i want to get the id's of the datasourced-fetched items that have been selected by the user in the grid, and send them to the server for another purpose than CRUD.

      I have done this through GWTRPC before, but also by iterating and doing an "add" with a custom operationid so that in my serverside spring service know that i'm supposed to do that "other thing".

      In this particular case, i'm gonna send a custom formatted SMS to the users selected in the grid.

      Was just wondering what you'd do.

      Comment


        #4
        The fact that you're sending an SMS is the key piece of information that's needed to answer the question. This means it's clearly not CRUD.

        Many people look for some way to do a non-CRUD operation for the wrong reason, eg, they think it's not CRUD if it's not SQL, or some similar misconception.

        For your use case, which really isn't a CRUD operation, we recommend DataSource.performCustomOperation().

        Comment


          #5
          Why thanks. That's actually a piece of functionality i'd forgotten about. Will check!

          Comment


            #6
            Hey again,

            i'm actually having a bit of a problem as to how i'm to send the data we discussed.

            I have the following data i wish to send:

            1. selected users in the grid
            2. a string "message"
            3. a boolean

            I've tried all sorts of params-setting in the "customOperation" method.

            this is how i do it:
            Code:
            DSRequest req = new DSRequest();
            ListGridRecord[] sel = grid.getSelectedRecords();
            req.setAttribute("data", usersGrid.getSelectedRecords());
            ...
            userDS.performCustomOperation("send", new Record(), new DSCallback() {
                        @Override
                        public void execute(com.smartgwt.client.data.DSResponse response, Object o, DSRequest dsRequest) {
                            SC.say("response: " + response.getStatus());
                        }
                    }, req);
            this is the only way i could find to send the data to the server, if i set a custom parameter, for example

            Code:
            req.setAttribute("selected", usersGrid.getSelectedRecords());
            DataSource throws an exception for some reason. Same if i use the "data" parameter instead of the "new Record()"

            Now, the problem with the above that works, is that i cannot send any other data!

            Code:
            req.setAttribute("message", message.getValueAsString());
                    req.setAttribute("useMsisdn", useMsisdn.getValueAsBoolean());
            works if i don't set the "data" attribute as above, but is ignored otherwise.

            I also tried
            Code:
            Record data = new Record();
                    req.setAttribute("message", message.getValueAsString());
            and use that parameter as "data" in the customoperation method, no luck.


            So, my question is:

            Is there a way i haven't tried to send all the parameters i need to send in the request? I.e. the selected records, a string parameter and a boolean parameter?

            Input would be great...

            Comment


              #7
              Send data using the Record parameter to performCustomOperation().

              Comment


                #8
                HI! :)

                This is an old thread, but i just looked at this old code today. I am wondering about the serverside part of this. Right now, i have a "send()" method in a spring bean, it is called, and i extract the relevant data through the valuesmap in DSRequest. This works fine.

                However, In other server services where i perform CRUD operations, i have defined beans, and have those as request parameters, and smartgwt is smart enough to populate this bean when the spring method is called. However, for this "customOperation" i cannot get it to work. Optimally, i would just like to have a custom Java Bean as the parameter and being populated by the framework like in other places.

                Is this supposed to be possible with custom operations, or does it only work for CRUD?

                Comment


                  #9
                  You can simply use DataTools.setProperties() with the data if auto-population isn't working. That's the method that is used for auto-population for CRUD operations.

                  Comment

                  Working...
                  X