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

    Best practices Master/Details form

    Using SmartClientJS 10.0, but the question is not related to that particular version (it's more of a architectural question).

    I'm using a RubyOnRails back-end and want to create a Customer form. Customer has an id, name and other fields. But it also has detail records for (zero or more) addresses. I would like to create a form that POSTs everything in one request, without the need for a customer record to exist before addresses can be added in the form. Of course, when saving to the database, the customer gets created first and with the created id, the addresses will be saved to the database as well. This can all be done in one transaction.

    I've more or less created this with the CanvasItem example. When opening the form, I request JSON data that looks this:

      "status": 0,
      "response": {
        "data": {
          "id": 1,
          "name": "John Doe",
          "addresses": [
            { "id": 1, "street": "Down town street", "house_number": "1", "type": "shipping" },
            { "id": 2, "street": "Up town lane", "house_number": "2", "type": "billing" }
    I have troubles in POSTing the data and Rails treating the addresses as array. It suspect it needs "[]" in the name. I'm not sure yet, but if so, I don't know if that's possible and if it is, how? I've tried giving the form item with the grid a name that included the "[]" but the GET data probably should have that name as well and that's "hard" to program on the server (with "hard" I mean in a "Rails friendly way").

    But already being busy with this problem for hours (if not days) already, it made me wonder if this is the approach I need to chose. I could use any kind of advice, my main goal is to avoid the necessity of creating the customer beforehand to be able to create addresses.

    Right now, I don't use SmartClient's foreignKey solution, but maybe that's the way to go. I basically create a piece of JavaScript that defines all data sources from RubyOnRails "meta" data in my model classes (but that's off scope I guess).

    Anyone experience with Rails and SmartClient that could give advice? Thanks in advance.

    We would recommend using queuing, which is supported by RestDataSource and handles many cases beyond just posting a master-detail structure in one post. See the docs for details.

    About a field named something like "address[]" - no, we don't support non-identifier characters in field names, so this would require some kind of two-way transform between data being transferred to/from the server and in-memory structures in the browser, but this is a worse solution anyway.


      I will try to create some stand-along test cases. Master/details are so trivial, but I'm still having troubles implementing a solution that satisfies. So I will investigate further. Your answer probably forces me to change the server implementation. How would one send multiple attributes with the same name, or isn't that possible?



        Check out this example:


          Hi Dencel,

          Thanks for your reaction. I did look into that but this example has some differences:

          - It uses two grids, one being the master, the other the details
          - It doesn't allow create/update/delete actions on the order items (detail records)
          - It uses XML data sources backed by a Java Server
          - I am not sure if this works with the Professional Edition or that I require the Enterprise edition


            This even works with the LGPL + RestDataSource + custom server backing.

            You can have a form as master component and a listgrid as detailcomponent (with autoSaveEdits false).

            To save the whole you will start a transaction, call save on the form and then save on the listgrid. The last step is to send the transaction. This will send the entire transaction in one request to the server, where you can handle each request individual or as a whole (up to you). You can even reference results from the previous response in the request of the detail. (This is useful to set the foreignkey in the detail when adding a new record to the master).

            If you have a foreignkey in the Detail ds to the master ds you can even use fetchRelatedData on the listgrid when you set the record on the form.