0

I'm sure this is a total noob question and I'm missing a blatant error, but here goes anyway.

I have a command object:

public class LeadCommand {
    Integer OwnerId
    String FirstName
    String LastName
    String Email
    String Phone1
    String Company
    String StreetAddress1
    String City
    String State
    String PostalCode
    String Country
    String Leadsource

    static constraints = {
        OwnerId(blank: false)
        FirstName(blank: false)
        LastName(blank: false)
        Email(blank: false, email: true)
        Phone1(blank: false)
        Company(blank: false)
        StreetAddress1(blank: false)
        City(blank: false)
        State(blank: false)
        PostalCode(blank: false)
        Country(blank: false)
        Leadsource(blank: false)
    }
}

And a controller action:

def process = { LeadCommand cmd ->

    if (cmd.hasErrors()) {
        redirect(action: index)
    } else {
            // do stuff
    }
}

The command object is getting populated, but is not following the validation constraints that I setup. I've read through the docs a couple of times, but I must be missing something...

Thanks in advance

BTW - I'm using Grails 1.3.7

EDIT:

Here is some sample post data: (straight from params map)

[Phone:, 
OwnerId:1, 
Country:United States, 
LastName:, 
City:, 
PostalCode:, 
State:, 
Email:, 
Leadsource:, 
FirstName:, 
Submit:Submit, 
Company:, 
StreetAddress1:, 
action:process, 
controller:leadEntry]
Jay Prall
  • 5,295
  • 5
  • 49
  • 79
matmer
  • 621
  • 2
  • 5
  • 14

1 Answers1

4

Rename your command properties to use the standard Java naming convention of camel case with an initial lower case letter. Grails uses these conventions heavily and sometimes breaks if you don't follow them. For example:

public class LeadCommand {
    Integer ownerId
    String firstName
    String lastName
    String email
    String phone1
    String company
    String streetAddress1
    String city
    String state
    String postalCode
    String country
    String leadsource

    static constraints = {
        ownerId(blank: false)
        firstName(blank: false)
        lastName(blank: false)
        email(blank: false, email: true)
        phone1(blank: false)
        company(blank: false)
        streetAddress1(blank: false)
        city(blank: false)
        state(blank: false)
        postalCode(blank: false)
        country(blank: false)
        leadsource(blank: false)
    }
}
ataylor
  • 64,891
  • 24
  • 161
  • 189
  • This is what I was thinking as well. First letter capitalized on an attribute or method = :( – Kaleb Brasee Dec 12 '11 at 20:09
  • That did it! Thanks ataylor. I usually follow those conventions but was trying to take a shortcut (the data is getting passed on to another app the requires the caps), but apparently Grails no likey. Thanks again. – matmer Dec 12 '11 at 20:15