Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.4, 2.1.1
    • Fix Version/s: 2.4-RC1
    • Component/s: Data binding
    • Labels:
      None

      Description

      I don't think the bug discussed here http://archive.codehaus.org/lists/org.codehaus.grails.dev/msg/l2kd95c613f1004281236x5b1317c9xb0787a80413a2899@mail.gmail.com was ever JIRA'd.

      I created a simple domain class:

        class Book { 
            String title 
            String author 
            Float price 
        }
      

      and scaffolded it. I then created a new book from the UI with a valid title and author, but a price of "12.99skdfhaskfjh". No validation errors were triggered! The "skdfhaskfjh" suffix was silently removed and the value saved as 12.99

        Issue Links

          Activity

          Show
          Iván López added a comment - Another test case with Command Objects here: http://grails.1312388.n4.nabble.com/Casting-of-named-params-not-working-with-Command-Objects-td4640199.html
          Hide
          Graeme Rocher added a comment -

          Jeff - maybe look at this as part of your data binding work

          Show
          Graeme Rocher added a comment - Jeff - maybe look at this as part of your data binding work
          Hide
          Peter N. Steinmetz added a comment -

          On Jan 2 there was another mention of this, which looks like the same bug.

          bhushan154 <bhushan154@gmail.com> wrote:

          I have an integer variable in a domain class
          class Equipment
          {
          Integer equipmentNumber
          }

          In the form, when I provide input as 123abc, it is being accepted and stored
          as 123. How do I make it throw a validation fail message instead?

          Show
          Peter N. Steinmetz added a comment - On Jan 2 there was another mention of this, which looks like the same bug. bhushan154 <bhushan154@gmail.com> wrote: I have an integer variable in a domain class class Equipment { Integer equipmentNumber } In the form, when I provide input as 123abc, it is being accepted and stored as 123. How do I make it throw a validation fail message instead?
          Hide
          Greg Waters added a comment -

          Was this issue fixed and release with 2.3? I am currently running into the same error with 2.3.7.

          If I use the binding by:
          MyCommandObj testObj = new MyCommandObject(params) I get a GroovyCastException thrown

          But if I use the bindData() or def index(MyCommandObj testObj) I get the same results as i did with older grails versions with no errors on the command objects.

          Show
          Greg Waters added a comment - Was this issue fixed and release with 2.3? I am currently running into the same error with 2.3.7. If I use the binding by: MyCommandObj testObj = new MyCommandObject(params) I get a GroovyCastException thrown But if I use the bindData() or def index(MyCommandObj testObj) I get the same results as i did with older grails versions with no errors on the command objects.
          Hide
          Jeff Scott Brown added a comment -

          Greg,

          As far as I can tell, the problem you are describing is not the same one described in this issue. when you do something like this...

          def mco = new MyCommandObject(params) 
          

          You are invoking the default Map constructor provided by Groovy which doesn't have anything to do with Grails data binding system. If MyCommandObject were a domain class the Map constructor does use the data binding system but that is not the case for non domain classes. When you use bindData(...) or you let Grails do the data binding for you with def index(MyCommandObject obj) then the Grails data binding system is used.

          If that doesn't make sense or if you disagree, file a new JIRA and attach a simple sample app.

          Thanks for the feedback.

          Show
          Jeff Scott Brown added a comment - Greg, As far as I can tell, the problem you are describing is not the same one described in this issue. when you do something like this... def mco = new MyCommandObject(params) You are invoking the default Map constructor provided by Groovy which doesn't have anything to do with Grails data binding system. If MyCommandObject were a domain class the Map constructor does use the data binding system but that is not the case for non domain classes. When you use bindData(...) or you let Grails do the data binding for you with def index(MyCommandObject obj) then the Grails data binding system is used. If that doesn't make sense or if you disagree, file a new JIRA and attach a simple sample app. Thanks for the feedback.
          Hide
          Greg Waters added a comment -

          Thanks Jeff.

          I am still having the issue with the the Grails data binding system below is what I am using and is similar to this issue. This should cause the Command object to have errors but the output shows that in version 2.2.0 and 2.3.7 the object is clean.

          TestMyDoubleController.groovy
          package testnewdouble 
          
          import grails.validation.ValidationException 
          import org.springframework.validation.Errors 
          
          class TestMyDoubleController { 
          
              def home(DoubleCommand d) { 
                  println"Validate Command ${d.hasErrors()}" 
                  println"params ${params}" 
                  render "\nparams: ${params} \nNew Double ${d.d} New Integer ${d.a}\nErrors:${d.hasErrors()}" 
             } 
          } 
          
          @grails.validation.Validateable 
          class DoubleCommand { 
              Double     d 
              Integer    a 
          } 
          
          curl http://localhost:8080/TestNewDouble/TestMyDouble/home?d=33.o9\&a=1w1 
          
          output: 
          params: [d:33.o9, a:1w1, action:home, format:null, controller:TestMyDouble] 
          New Double 33.0 New Integer 1 
          
          Show
          Greg Waters added a comment - Thanks Jeff. I am still having the issue with the the Grails data binding system below is what I am using and is similar to this issue. This should cause the Command object to have errors but the output shows that in version 2.2.0 and 2.3.7 the object is clean. TestMyDoubleController.groovy package testnewdouble import grails.validation.ValidationException import org.springframework.validation.Errors class TestMyDoubleController { def home(DoubleCommand d) { println "Validate Command ${d.hasErrors()}" println "params ${params}" render "\nparams: ${params} \nNew Double ${d.d} New Integer ${d.a}\nErrors:${d.hasErrors()}" } } @grails.validation.Validateable class DoubleCommand { Double d Integer a } curl http://localhost:8080/TestNewDouble/TestMyDouble/home?d=33.o9\&a=1w1 output: params: [d:33.o9, a:1w1, action:home, format:null, controller:TestMyDouble] New Double 33.0 New Integer 1
          Hide
          Jeff Scott Brown added a comment -

          I see what the problem is. The issue was only kind of fixed. It is fixed, but only in a way that doesn't relate to a real running app so the bottom line is that it isn't fixed. We will get it straightened out. Thanks again for the feedback.

          Show
          Jeff Scott Brown added a comment - I see what the problem is. The issue was only kind of fixed. It is fixed, but only in a way that doesn't relate to a real running app so the bottom line is that it isn't fixed. We will get it straightened out. Thanks again for the feedback.

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              Donald
            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Last Reviewed:

                Development