0

I am recently working on grails and would like to know how to do more complex scaffolding

For example, if I want to Scaffold a class

class Book{
  Author a
  Publisher p

  // ....
}

Author class

class Author{
   String firstName
   String lastName
   // ...
}

Publisher class

class Publisher{
    String name
    String address
    // ....
}

Now if I have a BookController

class BookController{
   static scaffold = true;
}

I have a layout of

Author        Publisher

However if I want a layout with

AuthorID        AuthorFirstName        AuthorLastName        PublisherName        PublisherAddress

I have looked through the http://grails.org/doc/latest/guide/scaffolding.html, however, I am unable to set it to the given property. I would like to know I am able to accomplish it? A tutorial would be helpful.

user288231
  • 995
  • 2
  • 13
  • 24

2 Answers2

0

The scaffolding plugin within Grails is not designed to handle these types of complex views out of the box. You have a few options:

  1. Use the install-templates command and modify the scaffolding templates to handle your needs.

  2. Re-design your domain class to use embedded Author and Publisher. This will change the scaffolding output, but it also will change a lot more too. I wouldn't use this option unless you understand all the changes this will make to your domain model.

  3. Generate the code using scaffolding then customize the output to suit your needs.

Of the three options presented here I would recommend the third as it makes the most sense to address the narrow scope of your issue.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73
  • Do you have any tutorials that would allow me to know how I can do option 3? How I am able to customize my output? I have been searching, but do not know where to start – user288231 Aug 25 '14 at 12:58
  • To better understand the scaffolding in both cases you should read the documentation: http://grails.org/doc/latest/guide/scaffolding.html using `generate-all MyDomainClassName` will generate the controller and views. From there you can just edit them as you like. – Joshua Moore Aug 25 '14 at 13:59
0

You could also use transients. But transients aren't displayed by default.

You need to modify the templates and explicitly hide otherwise hidden fields using constraints i.e. id

NOTE: code below untested, for illustration purposes only.

//optional, but allows code completion in IDE ;-P
String authorName

String getAuthorName(){
   return a.firstName + ' ' + a.lastName
}

static transients = [authorName:String]

static constraints = {
   id(display:false)
}
Community
  • 1
  • 1
awltux
  • 521
  • 4
  • 5