Results 1 to 2 of 2

Thread: Fill two domain classes through one view

  1. #1
    Join Date
    May 2011
    Posts
    3

    Unhappy Fill two domain classes through one view

    Hi everybody. First of all I want to tell you that I am a Grails beginner so my question could sound a little silly. I've been researching a little about Grails and I learned that it is enough to write scaffold=true in the domain class file (of course this is the easiest way) and we have all the GUI that implements all the CRUD functionality but with this we can fill just one entity, or at least it is all I know (I told you I am a beginner). The deal is that I want to have just one GSP view to fill an invoice (I am developing a clothing store app). You know there is basically two entities, the first one is the INVOICE itself and the second one is the DETAIL of the invoice. So, one INVOICE can have many DETAILs, like this:
    INVOICE
    --------
    CUSTOMER NAME: Manuel Calles
    ADDRESS: 8th Street
    DATE: 2011/5/30

    DETAIL
    -------
    ITEM | DESCRIPTION | QUANTITY | UNITARY COST | TOTAL |
    -------------------------------------------------------------
    a1 | Toshiba Laptop| 1 | 800 | 800 |
    b3 | Optical mouse | 2 | 10 | 20 |
    -------------------------------------------------------------
    TOTAL 820

    And I want just one view to fill all this information just like the software some stores are using do. How can I do this with Grails.

    Thanks in advance.

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    You will have to move away from scaffolding and start implementing your own custom views and controller actions. A single page requires one controller action and optionally one view. You will then need a second controller action that handles the submission of the invoice + detail form.

    You can see what code is behind the scaffolding by running the command
    Code:
    grails generate-all org.example.Invoice
    (be sure to replace 'org.example' with your package name). You can then customise the code in InvoiceController and grails-app/views/invoice/*.gsp.

    If you have any more questions, feel free to post them here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •