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]
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)
}
}