Grails Scaffolding Plugin
  1. Grails Scaffolding Plugin
  2. GPSCAFFOLD-62

Scaffolded views only available for scaffolded actions

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      Consider a scaffolded controller, whose views are all scaffolded as well. It is not possible to add an action to the controller that tries to render one of those scaffolded views, e.g.:

      class TestController {
      
          def scaffold = true
      
          def testaction = { render( view: "create" ) }
      }
      

      This is because ScaffoldingViewResolver's loadView-method requires the current action to be a scaffolded one - I do not understand why.
      The workaround is to generate the view - even though there's no real need to.

        Issue Links

          Activity

          Bart Robeyns created issue -
          Jeff Scott Brown made changes -
          Field Original Value New Value
          Issue Type Bug [ 1 ] Improvement [ 4 ]
          Priority Major [ 3 ] Minor [ 4 ]
          Component/s Scaffolding [ 10423 ]
          Component/s Controllers [ 10414 ]
          Hide
          cdeszaq added a comment -

          I would argue that this is a bug with the scaffolding, and not an improvement. To me, when something doesn't work as expected, it's a bug, especially in a framework that is build around a strong sense of Least Surprises.

          Show
          cdeszaq added a comment - I would argue that this is a bug with the scaffolding, and not an improvement. To me, when something doesn't work as expected, it's a bug, especially in a framework that is build around a strong sense of Least Surprises.
          Hide
          Robert Freudenreich added a comment -

          As described here, a workaround is to add the custom action to the list of scaffolded actions in BootStrap.

          Example:

          class BootStrap { 
            def scaffoldedActionMap 
          
            def init = { ctx -> 
              scaffoldedActionMap['test'] << 'testaction' 
            } 
          }
          
          Show
          Robert Freudenreich added a comment - As described here , a workaround is to add the custom action to the list of scaffolded actions in BootStrap. Example: class BootStrap { def scaffoldedActionMap def init = { ctx -> scaffoldedActionMap['test'] << 'testaction' } }
          Hide
          Robert Freudenreich added a comment -

          It might occur, that the code in BootStrap is executed before the scaffoldedActionMap has been completely generated. In this case, it is possible that the key for a controller does not yet exist in the map and that your changes are overwritten later. A workaround for this problem can be to delay the addition of actions until the controller has been processed by the Scaffolding plugin and the key exists in the map.

          Example code which sleeps until all keys are available and times out after 10 seconds:

          class BootStrap { 
            def scaffoldedActionMap 
          
            def init = { ctx -> 
              addToScaffoldedActionMap(['test': ['testaction']])
            }
          
            def addToScaffoldedActionMap(Map toAdd) {
              for (int i=0; i<10; i++) {
                Map addNow = toAdd.findAll { scaffoldedActionMap[it.key] }
                
                addNow.each {
                  scaffoldedActionMap[it.key] += it.value
                  toAdd.remove(it.key)
                }
          
                if (toAdd.size() > 0) {
                  Thread.sleep(1000);
                } else {
                  break;
                }
              }
            }
          }
          
          Show
          Robert Freudenreich added a comment - It might occur, that the code in BootStrap is executed before the scaffoldedActionMap has been completely generated. In this case, it is possible that the key for a controller does not yet exist in the map and that your changes are overwritten later. A workaround for this problem can be to delay the addition of actions until the controller has been processed by the Scaffolding plugin and the key exists in the map. Example code which sleeps until all keys are available and times out after 10 seconds: class BootStrap { def scaffoldedActionMap def init = { ctx -> addToScaffoldedActionMap(['test': ['testaction']]) } def addToScaffoldedActionMap(Map toAdd) { for ( int i=0; i<10; i++) { Map addNow = toAdd.findAll { scaffoldedActionMap[it.key] } addNow.each { scaffoldedActionMap[it.key] += it.value toAdd.remove(it.key) } if (toAdd.size() > 0) { Thread .sleep(1000); } else { break ; } } } }
          Lari Hotari made changes -
          Assignee Lari Hotari [ lhotari ]
          Lari Hotari made changes -
          Project Grails [ 10020 ] Grails Scaffolding Plugin [ 11294 ]
          Key GRAILS-8995 GPSCAFFOLD-62
          Workflow Grails2 [ 104040 ] jira [ 107070 ]
          Affects Version/s 2.0.3 [ 13094 ]
          Assignee Lari Hotari [ lhotari ] Burt Beckwith [ burtbeckwith ]
          Component/s Scaffolding [ 10423 ]
          Hide
          Lari Hotari added a comment -

          Fixed by this commit: https://github.com/grails-plugins/grails-scaffolding/commit/f5a6209ad50d9d03ca588ea9fe017e6720ad7c9b . Will be release in scaffolding plugin version 2.0.1 together with Grails 2.3.1

          Show
          Lari Hotari added a comment - Fixed by this commit: https://github.com/grails-plugins/grails-scaffolding/commit/f5a6209ad50d9d03ca588ea9fe017e6720ad7c9b . Will be release in scaffolding plugin version 2.0.1 together with Grails 2.3.1
          Lari Hotari made changes -
          Link This issue is duplicated by GPSCAFFOLD-65 [ GPSCAFFOLD-65 ]
          Lari Hotari made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.0 [ 13474 ]
          Resolution Fixed [ 1 ]
          Lari Hotari made changes -
          Link This issue is duplicated by GRAILS-4691 [ GRAILS-4691 ]
          Lari Hotari made changes -
          Link This issue is related to GRAILS-9920 [ GRAILS-9920 ]

            People

            • Assignee:
              Burt Beckwith
              Reporter:
              Bart Robeyns
            • Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: