Grails
  1. Grails
  2. GRAILS-8795

The method in the Controllers begain with "get" will be invoked automaticly

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.1
    • Fix Version/s: None
    • Component/s: Controllers
    • Labels:
    • Environment:
      windows xp sp3,idea11.0.2,jdk1.6
    • Patch attached:
      Yes

      Description

      I didn't invoked the method start with get.But when I visited MainController,the method start with get had been executed.Pls find attached.

        Issue Links

          Activity

          Hide
          Bobby Warner added a comment -

          This is not a bug, but rather a feature of the Groovy language. Methods that start with get are treated as a property getter and called on object creation. So, you simply can't create actions that start with get. You could always use custom URL mappings if you wanted "get" in the actual URL. I recommend closing this issue. Thanks, Bobby

          Show
          Bobby Warner added a comment - This is not a bug, but rather a feature of the Groovy language. Methods that start with get are treated as a property getter and called on object creation. So, you simply can't create actions that start with get. You could always use custom URL mappings if you wanted "get" in the actual URL. I recommend closing this issue. Thanks, Bobby
          Hide
          Rodrigo Rosenfeld Rosas added a comment -

          Isn't this a duplicate of this one?

          http://jira.grails.org/browse/GRAILS-8485

          Show
          Rodrigo Rosenfeld Rosas added a comment - Isn't this a duplicate of this one? http://jira.grails.org/browse/GRAILS-8485
          Hide
          Rodrigo Rosenfeld Rosas added a comment -

          And this is not a feature since Groovy won't automatically call all property methods when you create a new instance of some class. Grails is doing that.

          Show
          Rodrigo Rosenfeld Rosas added a comment - And this is not a feature since Groovy won't automatically call all property methods when you create a new instance of some class. Grails is doing that.
          Hide
          Bobby Warner added a comment -

          Yup, you're right. I should have said Grails, not Groovy. Thanks, Bobby

          Show
          Bobby Warner added a comment - Yup, you're right. I should have said Grails, not Groovy. Thanks, Bobby
          Hide
          Jeff Scott Brown added a comment -

          This issue was reported against Grails 2.0.1. Can the original reporter confirm that he really is seeing this in 2.0.1? There were some relevant changes made before 2.0.1 was released (GRAILS-8594).

          Thanks.

          Show
          Jeff Scott Brown added a comment - This issue was reported against Grails 2.0.1. Can the original reporter confirm that he really is seeing this in 2.0.1? There were some relevant changes made before 2.0.1 was released ( GRAILS-8594 ). Thanks.
          Hide
          Bobby Warner added a comment -

          Good catch Jeff! I should have actually tested it. I was just going off of what I had observed previously. This is no longer an issue in Grails 2.0.1. I just tested it with a sample app using 2.0.1 and actions that start with get are no longer called on object creation. Thanks, Bobby

          Here was my test controller. Visiting /foo/index does not print 'one' and 'two' like it used to with previous versions.

          package gettest
          class FooController {
          def index()

          { render 'index' }

          def getOne()

          { println 'one' }

          def getTwo()

          { println 'two' }

          }

          Show
          Bobby Warner added a comment - Good catch Jeff! I should have actually tested it. I was just going off of what I had observed previously. This is no longer an issue in Grails 2.0.1. I just tested it with a sample app using 2.0.1 and actions that start with get are no longer called on object creation. Thanks, Bobby Here was my test controller. Visiting /foo/index does not print 'one' and 'two' like it used to with previous versions. package gettest class FooController { def index() { render 'index' } def getOne() { println 'one' } def getTwo() { println 'two' } }
          Hide
          Rodrigo Rosenfeld Rosas added a comment -

          So it seems there are at least 3 duplicates. Maybe it's time to also close this one and 8485 if this was really fixed (I haven't tested as I've already changed all by getXXX action names).

          Show
          Rodrigo Rosenfeld Rosas added a comment - So it seems there are at least 3 duplicates. Maybe it's time to also close this one and 8485 if this was really fixed (I haven't tested as I've already changed all by getXXX action names).
          Hide
          Jeff Scott Brown added a comment -

          Bobby,

          I don't think that is a good test as it doesn't trigger the problematic scenario. I think this does:

          grails-app/controllers/com/demo/DemoController.groovy
          package com.demo
          
          class DemoController {
          
              def index() { 
                  render view: 'index'
              }
              
              def getSomething() {
                  println 'get something'
              }
          }
          

          I think this code shows that the problem still exists in 2.0.1.

          Show
          Jeff Scott Brown added a comment - Bobby, I don't think that is a good test as it doesn't trigger the problematic scenario. I think this does: grails-app/controllers/com/demo/DemoController.groovy package com.demo class DemoController { def index() { render view: 'index' } def getSomething() { println 'get something' } } I think this code shows that the problem still exists in 2.0.1.
          Hide
          Jeff Scott Brown added a comment -

          I think the problem is that if you do something like:

          render 'index'
          

          ...then Grails does not need to construct a model. If you do something like:

          render view: 'index'
          

          ...then Grails does need to construct a model and that leads to the invocation of the property getters.

          Show
          Jeff Scott Brown added a comment - I think the problem is that if you do something like: render 'index' ...then Grails does not need to construct a model. If you do something like: render view: 'index' ...then Grails does need to construct a model and that leads to the invocation of the property getters.

            People

            • Assignee:
              Unassigned
              Reporter:
              沙舟狼客
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Last Reviewed:

                Development