Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails Detailed Scaffolding #26

Closed
salehmamdouh1984 opened this issue Jun 14, 2016 · 22 comments
Closed

Grails Detailed Scaffolding #26

salehmamdouh1984 opened this issue Jun 14, 2016 · 22 comments
Labels

Comments

@salehmamdouh1984
Copy link

salehmamdouh1984 commented Jun 14, 2016

In Grails 3.x or even before, the generated gsp-s contain very concise code.
All of the form fields and input are dynamically generated by a tag "<f:all bean="your_domain_object"/>

However, I remember, in earlier versions of Grails, the generated gsps would allow more control and more verbose. What I mean, is that, there is no call to "<f:all bean="your_domain_object"/> and each control is rendered on the generated gsp file.
For example

<gsp:input property="#{user.name}" /> ... etc

Is this feature still supported by the latest Grails version ? Can it be brought back as it enables much more flexibility.

@jeffscottbrown
Copy link
Member

If #22 were fixed, you could customize the templates to generate the exact same code that the older versions of scaffolding generated.

@salehmamdouh1984
Copy link
Author

Oh my God!
That feature is actually half of Grails ....

When I first wrote the description of the issue, the code was not visible because I did not put it between quote tags. Now I fixed and the code is there.

@jeffbrown Can you please have a look again at my bug description after I corrected its description and confirm to me this will be solved by #22

Thanks

@graemerocher
Copy link
Member

The new version of scaffolding is built on the fields plugin, which provides complete control of customising the output. See https://grails-fields-plugin.github.io/grails-fields/guide/customizingFieldRendering.html

@graemerocher
Copy link
Member

@salehmamdouh1984
Copy link
Author

salehmamdouh1984 commented Jun 14, 2016

Oh my God!! That that explained many things ....

So in this case, the gap would mostly contain just instances of the field tag instead of the infamous f:all ... That seems convenient ... Since the field already has a wrapper and a widget.

And as I understood from the documentation, I can write any wrappers and widgets and use them for any field I want.

@salehmamdouh1984
Copy link
Author

salehmamdouh1984 commented Jun 14, 2016

@graemerocher
One more question ...
How supported in Grails can I write a script to generate gap pages ?
For example, if I have a domain class Employee(name, id, age), then I want the generated gap to contain those fields :

<f:field bean="person" property="age"/>
<f:field bean="person" property="id"/>
<f:field bean="person" property="name"/>

How much support is there in Grails ?

@jeffscottbrown
Copy link
Member

You can customize the templates to generate pretty much anything you like, including the example you described there.

@salehmamdouh1984
Copy link
Author

salehmamdouh1984 commented Jun 15, 2016

I just tried to create an application with grails. Just doing nothing, just create a new grails app, and here is what I got :

Error Error occurred running Grails CLI: Bad <init> method call from inside of a branch
Exception Details:
  Location:
    org/grails/cli/interactive/completers/AllClassCompleter.<init>()V @123: invokespecial
  Reason:
    Error exists in the bytecode
  Bytecode:
    0x0000000: b800 144c 04bd 0016 5903 2b12 1732 2b12
    0x0000010: 1832 2b12 1932 121b 2b12 1c32 121e b900
    0x0000020: 2402 0012 26b9 002a 0400 b900 2d02 00bb
    0x0000030: 002f 5912 0212 02b7 0032 b900 3503 0012
    0x0000040: 37b8 003d c000 3712 37b8 0041 5359 10ff
    0x0000050: 1204 b800 452a 5fab 0000 003f 0000 0002
    0x0000060: 1374 8337 0000 0019 4ad1 f42c 0000 002a
    0x0000070: 5f5a 0312 37b8 004b c000 37b7 004e a700
    0x0000080: 225f 5a59 0332 121b b800 51c0 001b 5f57
    0x0000090: b700 54a7 000d bb00 5659 1258 b700 5bbf
    0x00000a0: 572a b600 5f4d 2c2a 5fb5 0061 2c57 b1  
  Stackmap Table:
    full_frame(@112,{UninitializedThis,Object[#101]},{Object[#103],UninitializedThis})
    full_frame(@129,{UninitializedThis,Object[#101]},{Object[#103],UninitializedThis})
    full_frame(@150,{UninitializedThis,Object[#101]},{Object[#103],UninitializedThis})
    full_frame(@160,{Object[#2],Object[#101]},{Object[#103]})
 (Use --stacktrace to see the full trace)

@graemerocher
Copy link
Member

probably a JVM bug, make sure your JVM is the most recent version

@jeffscottbrown
Copy link
Member

@salehmamdouh1984
Copy link
Author

So, I updated to the latest Grails version.
Two questions go here
1- If I have an existing project already started with a little bit earlier version, is there anything special I need to do to upgrade to the newest version ? Can I just the commands of the latest version directly without any risk ?

2- @jeffbrown

You can customize the templates to generate pretty much anything you like
How can I do that ? An examples ?
How can I change the template so that the code generate is different ?
Currently the template has

I want to change the template to generate the actual field <f:field depending on the fields of the domain class. So this is a code generation thing.

@jeffscottbrown
Copy link
Member

1- If I have an existing project already started with a little bit earlier version, is there anything special I need to do to upgrade to the newest version ? Can I just the commands of the latest version directly without any risk ?

Both of those questions call for a discussion and neither are directly related to the issue here. Better forums for those questions are our community Slack channel at http://grails.slack.com and our mailing list at https://groups.google.com/forum/#!forum/grails-dev-discuss.

@salehmamdouh1984
Copy link
Author

@jeffbrown @graemerocher
I posted the question on the mailing list but nobody ever responds. You mentioned in your earlier reply that everything I do should be doable.

Any code samples ? Documentations ?

Again I am asking about code generation from within the script. Template create only copies the template files and replaces some place holders with actual bean names :(.

You mentioned before that templates is the way to do it, but that's not the case ....

@jeffscottbrown
Copy link
Member

You mentioned before that templates is the way to do it, but that's not the case

Yes, I think it is.

The dynamic templates appear to work. It may be that the information you need isn't being made available in the model.

@salehmamdouh1984
Copy link
Author

Ok.
Probably the best way to do that is

  1. Doing File IO from my custom script to generate and write to files ...
  2. Loop over the attributes of the entity and generate tags accordingly. Like the code in
    f:all (It loops through attributes and calls the field functionality). Code is in FormFieldsTagLib.groovy

I thought there could be easier way in Grails or code to reuse since ancient versions of Grails used to do that.

@jeffscottbrown
Copy link
Member

The issue is that I don't think you have access to the relevant Class in the scaffolding templates right now. I think you have access to the class name, but not the Class, which you might need in order to iterate over the properties. I am not 100%, but I think that is the case.

@salehmamdouh1984
Copy link
Author

I can see the source code of the class and related methods, so why not copying the source and change it to support these changes ...

@jeffscottbrown
Copy link
Member

You have the same conversation happening in 3 separate places right now including here, the mailing list and Slack. I propose that you carry on the conversation on the mailing list.

@salehmamdouh1984
Copy link
Author

@jeffbrown
ok ......

@zbubric
Copy link

zbubric commented Jul 27, 2017

Hi,

As it is already mentioned in previous comments (as well as on few different conversations around) it should be possible to owerride default generate-* scripts in order to provide additional data to template (in this case a list of domain properties). However, I can't find any examples or tutorials how to do it so I'm interested is there any docs/example hoe to do it? Or, at least, a hint how to start? Thx in advance

@jameskleeh
Copy link
Contributor

jameskleeh commented Jul 27, 2017

@zbubric That isn't possible. You would have to create a custom command http://docs.grails.org/latest/guide/commandLine.html#creatingCustomCommands

There is also a generic scaffolding library available for use https://github.com/grails/scaffolding

See https://github.com/grails-plugins/grails-angularjs-scaffolding for an example of it being used

@zbubric
Copy link

zbubric commented Jul 27, 2017

@jameskleeh Thx! In matter of fact, I didn't notice that this is not generic scaffolding library that you mentioned in the post :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants