Announcement Announcement Module
Collapse
No announcement yet.
Scaffolding: Difference between create/edit views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scaffolding: Difference between create/edit views

    Hi all,

    I found it quite odd that associations are handled differently in create and edit views. Reason is the following line from create.gsp scaffolding template:

    Code:
    if (!Collection.class.isAssignableFrom(p.type)) {
    I found other ppl wondering about this when searching the web a bit. And I can imagine a good reason for this difference. When you've a bidirectional relationship and use the "add" button it'll take you away from your form and you'll loose the data you probably already entered.

    But if that's the only reason, then a simple check like this would take care of bidirectional hasMany relations:

    Code:
    if (!p.isBidirectional()) {
    I tried it and it works fine. But I guess there's another reason for this difference in the standard grails scaffolding templates?! Am I missing something important or will my version be just fine? If there's not, I suggest to adapt this change to the standard scaffolding templates as this difference on add/edit seems to confuse users.

    Cheers,
    Thomas
    Last edited by ThomasBecker; Apr 9th, 2011, 09:53 AM. Reason: Typo in code

  • #2
    Another similar issue I had is that you can't remove all associated objects with the default scaffolding. Root cause is that if you deselect everything in a select box, nothing from that select box is transferred to the server.

    I fixed it by adding a hidden field with empty value for all Collection types. Need to do more testing to see if it has sideeffects.

    Here's the changes I did for both the topic I described in the first post and the one described herd:

    Code:
    diff --git a/content-server-grails/src/templates/scaffolding/create.gsp b/content-server-grails/src/templates/scaffolding/create.gsp
    index f638064..2e6dcac 100644
    --- a/content-server-grails/src/templates/scaffolding/create.gsp
    +++ b/content-server-grails/src/templates/scaffolding/create.gsp
    @@ -34,7 +34,7 @@
                                 display = true
                                 boolean hasHibernate = PluginManagerHolder.pluginManager.hasGrailsPlugin('hibernate')
                                 props.each { p ->
    -                                if (!Collection.class.isAssignableFrom(p.type)) {
    +                                if (!p.isBiDirectional()) {
                                         if (hasHibernate) {
                                             cp = domainClass.constrainedProperties[p.name]
                                             display = (cp ? cp.display : true)
    diff --git a/content-server-grails/src/templates/scaffolding/edit.gsp b/content-server-grails/src/templates/scaffolding/edit.gsp
    index 41ee197..2c20866 100644
    --- a/content-server-grails/src/templates/scaffolding/edit.gsp
    +++ b/content-server-grails/src/templates/scaffolding/edit.gsp
    @@ -41,7 +41,11 @@
                                         cp = domainClass.constrainedProperties[p.name]
                                         display = (cp?.display ?: true)
                                     }
    -                                if (display) { %>
    +                                                               
    +                                if (display) { 
    +                                                                       if (Collection.class.isAssignableFrom(p.type)) {
    +                                                                               %> <g:hiddenField name="${p.name}" value=""/> <%
    +                                                                       }       %>
                                 <tr class="prop">
                                     <td valign="top" class="name">
    If you think it makes sense to get one or both of these changes into the grails scaffolding templates, let me know. I will create the JIRA issues then.

    Comment


    • #3
      Hi Thomas,

      Rob Fletcher is currently working on the scaffolding, so if you raise a JIRA issue and post the URL here, I will assign it to him so he can take a look.

      Thanks,

      Peter

      Comment


      • #4
        Done:

        http://jira.grails.org/browse/GRAILS-7446
        http://jira.grails.org/browse/GRAILS-7447

        Comment


        • #5
          Comment to my first post. I had to enhance the if clause above to:

          Code:
          if (!p.isBidirectional() || p.isManyToOne()) {
          To get ManyToOne select boxes being displayed.

          Comment


          • #6
            thanks for info.............



            -----------------------
            Clamps, Nuts

            Comment

            Working...
            X