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

          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 ; } } } }
          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

            People

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

              Dates

              • Created:
                Updated:
                Resolved: