简体   繁体   English

Grails命令对象未验证

[英]Grails command object not validating

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 顺便说一句-我正在使用Grails 1.3.7

EDIT: 编辑:

Here is some sample post data: (straight from params map) 以下是一些示例发布数据:(直接来自params地图)

[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. 重命名命令属性,以使用驼峰大小写的标准Java命名约定和小写字母开头。 Grails uses these conventions heavily and sometimes breaks if you don't follow them. Grails大量使用这些约定,如果您不遵循它们,有时会中断。 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)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM