Announcement

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

    How to get saved record/primary key

    Hi,

    I have a one-to-many relationship when saving a form and a grid, the form contains 'ONE', and the grid expresses the 'MANY' records. Now when i click on the save button, it should save the 'ONE' record, and save the 'MANY' records.

    Usually this is done via ORM like Hibernate or iBatis, but i m trying not to implement any of these frameworks, and use SmartGwt pure SQL datasource instead, how should i save this One-To-Many? Do i save the ONE first, get returned primary key and then save the Many? Will Queue be helpful in this case?

    Please help, i m really stuck at this point, need your help urgently! Thanks!

    #2
    This exact use case is illustrated here.

    Comment


      #3
      Hi Iso, thanks for the help, it works really well!

      Comment


        #4
        Hi Iso,

        there's another question about the save, could you plz help?

        i want to reset the form and the ListGrid after the data is saved, but some of the fields are required, when i write code like in the use case:
        Code:
        		
        		RPCManager.startQueue();
        		formManager.saveData();
        		gridItems.saveAllEdits();
        		RPCManager.sendQueue();
        
        		formManager.editNewRecord();
        		gridItems.setData((ListGridRecord[])null);
        The above code does the save pretty well, but if a required field is not filled in, the queue won't be saved, but it will still execute the last 2 lines of code, which reset the DynamicForm and the ListGrid.

        I tried to use a DSCallback in the formManager.saveData(DSCallback) to identify if the DSResponse.getStatus() is STATUS_SUCCESS or not, but it doesn't work because the callback comes back later than the code that is to be executed, here are some sample code:

        Code:
        		
        		RPCManager.startQueue();
        		formManager.saveData(new DSCallback() {
        			public void execute(DSResponse response, Object rawData, DSRequest request) {
        				SC.say("Status = " + response.getStatus());
        				saved = response.getStatus() == DSResponse.STATUS_SUCCESS;
        			}
        		});
        		gridItems.saveAllEdits();
        		RPCManager.sendQueue();
        		if(saved) {
        			formManager.editNewRecord();
        			gridItems.setData((ListGridRecord[])null);
        			saved = false;
        		}
        the class variable 'saved' is set to false initially, and it is always false because 'if(saved)' gets executed earlier than the DynamicForm save callback.

        could you help me with it? Thanks!

        Comment


          #5
          I've resolved the problem by using:
          Code:
          if(DynamicForm.validate()){
             DynamicForm.editNewRecord();
             ListGrid.setData((ListGridRecord[])null);
          }
          but what if i want to handle the server thrown exceptions?

          Comment


            #6
            If the server throws exceptions, you will end up in central error handling in RPCManager (see the HandleErrorCallback). In that situation you may not want to clear out the widgets - you'll need to think through your error scenarios and how you want to handle them.

            Note another way to detect *successful* completion is to add a callback to the last operation submitted in the queue (the saveAllEdits() call in this case). We will also be adding an optional callback to sendQueue() (already exists in SmartClient).

            Comment


              #7
              thanks Iso. The central error handling in RPCManager was actually the first thing i thought of. i think i asked this question in another thread, that the RPCManager.setHandleErrorCallback(HandleErrorCallback()) seems to be like a global configuration, but i still haven't figured out how to assign it to a specific action.

              on the other hand, i also tried adding a callback to the last operation in the queue, in my case it's a ListGrid.saveAllEdits()

              Code:
              		gridConnoteItems.saveAllEdits(new Function() {
              			
              			public void execute() {
              				
              			}
              		});
              it doesn't return any response. the JavaDoc says that the callback will be fired on a successful save, does that mean i can clear up the form inside the 'execute(){}'?

              Thanks for your help!

              Comment


                #8
                The design behind global error handling is that ordinary errors like validation errors, which components understand, go to those components. Otherwise, unrecoverable errors go to global error handling so that you don't have to write error handling every single time you call an API that might fail due to server failure, network failure or other common causes.

                Yes, when the saveAllEdits() callback fires, as documented the save has succeeded and you can clear the form.

                Comment


                  #9
                  Hi Iso, i think i understand what you meant for the global error handling, is that to say, every application(or class?) can ever have only one RPCManager.setHandleErrorCallback?

                  Comment


                    #10
                    Right, one per application, to provide default error handling for unrecoverable errors for the entire application.

                    You can define error handling for a specific scenario by setting willHandleError true on the DSRequest/RPCRequest, which will cause your callback to be called even if there's an error.

                    Comment


                      #11
                      appreciate your help, and thanks for the quick replies!

                      Comment


                        #12
                        Is it possible the Queued Master / Detail Add using REST?

                        Comment


                          #13
                          Not with the RestDataSource, although it is possible to build your own queuing system and your own REST-like protocol for sending queued requests and processing the responses.

                          Comment


                            #14
                            thanks for the quick response.

                            I jave the possibility to use a java server ( i always use rest ) but no idea of ClientServerIntegration. What do you suggest? is better and safer to apply the server side java? thats mean change too much code or write to much server side code ? or keep in the client side with the rest-like ?

                            sorry for my english.

                            Comment


                              #15
                              It is absolutely better to install the full product if you have the option. It radically reduces the amount of code you have to write (if any) while producing a far better final application as well.

                              Take a look at the QuickStart Guide chapter on the Smart GWT Server Framework to get an idea of the features that come with using server-side integration.

                              Comment

                              Working...
                              X