Announcement

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

    SQLDataSource scenario

    Version: SmartGWT 3.0 Power

    I'm currently updating an application that was done with the LGPL version with a lot of server side Hibernate code and GWT-RPCs.

    Currently all my XML datasource files are several lines long: ID=x, serverType=sql, tableName=x, and autoDeriveSchema=true. I haven't had the need for anything complex yet as I'm just starting out with the CRUD operations for the app's static data and getting used to the idea of working with datasources only.

    One scenario I've come across I'm not sure what the best way is to implement: I have a screen that lets the user create a new parent object, and a ListGrid on that screen where they create child objects of the parent.

    In creating a new child:
    Code:
    cmdAdd.addClickHandler(new ClickHandler() {
    	@Override
    	public void onClick(ClickEvent event) {
    		Record record = new Record();
    		record.setAttribute("name", "New child");
    		record.setAttribute("parent_id", selectedParentID);
    		childGrid.startEditingNew(record);
    	}
    });
    This screen does both create and update, depending on whether its been given an instance of the parent record when its called (this is where selectedParentID comes from too)

    Obviously, this only works if the the parent instance already exists in the database.

    In the old version of the application, the objects were all created client side and sent over GWT-RPC and the Hibernate code dealt with whether it should save or edit, and I was able to control the order in which that happened, so even if the parent object was also new, I could save the parent first, update the client-created child objects with the new ID of the parent and then save the children.

    What should I be trying to do to maximise the use of SQLDataSource if I want to achieve the same thing of saving both parent and children at the same time?

    #2
    This example shows your exact scenario. If you don't want to do it via Transaction Chaining, a DMI also works - see server-side API RPCManager.findLastResponse().

    Comment


      #3
      Thats perfect thank you!

      My final implementation used a velocity expression to insert either the parent ID passed by the form when editing an existing parent or to use the $responseData.last to get the transaction's parent that was just inserted as found in the sample.

      Code:
      <!-- inject the parent ID required when adding children to a new parent only -->
      <operationBinding operationType="add">  
      	<values
          		fieldName="parent_id" 
          		value="#if (! $values.parent_id) $responseData.last('parentDS','add').id #else $values.parent_id #end"
          	/>
      </operationBinding>

      Comment

      Working...
      X