Rendering the params and gets all the data I submit
["address.address1":"reston1", "address":["address1":"reston1", "county":"fairfax", "zipcode":"20190", "address2":"reston2", "city":"reston"], "representative.telephone":"7702438000", "representative":["telephone":"7702438000", "fax":"7702438001"], "address.county":"fairfax", "address.zipcode":"20190", "user.lastName":"Chinthalapudi", "user":["lastName":"Chinthalapudi", "password":"spring", "email":"srinv9@gmail.com", "firstName":"Srinivas", "userName":"srisris"], "address.address2":"reston2", "create":"Create", "user.password":"spring", "user.email":"srinv9@gmail.com", "representative.fax":"7702438001", "user.firstName":"Srinivas", "user.userName":"srisris", "address.city":"reston", "company.companyName":"ATS", "company":["companyName":"ATS"], "action":"register", "controller":"employerRegistration"]
Error Stack
Field error in object 'com.srisris.wr.User' on field 'email': rejected value [null]; codes [com.srisris.wr.User.email.nullable.error.com.srisris.wr.User.email,com.srisris.wr.User.email.nullable.error.email,com.srisris.wr.User.email.nullable.error.java.lang.String,com.srisris.wr.User.email.nullable.error,user.email.nullable.error.com.srisris.wr.User.email,user.email.nullable.error.email,user.email.nullable.error.java.lang.String,user.email.nullable.error,com.srisris.wr.User.email.nullable.com.srisris.wr.User.email,com.srisris.wr.User.email.nullable.email,com.srisris.wr.User.email.nullable.java.lang.String,com.srisris.wr.User.email.nullable,user.email.nullable.com.srisris.wr.User.email,user.email.nullable.email,user.email.nullable.java.lang.String,user.email.nullable,nullable.com.srisris.wr.User.email,nullable.email,nullable.java.lang.String,nullable]; arguments [email,class com.srisris.wr.User]; default message [Property [{0}] of class [{1}] cannot be null]Field error in object 'com.srisris.wr.User' on field 'firstName': rejected value [null]; codes [com.srisris.wr.User.firstName.nullable.error.com.srisris.wr.User.firstName,com.srisris.wr.User.firstName.nullable.error.firstName,com.srisris.wr.User.firstName.nullable.error.java.lang.String,com.srisris.wr.User.firstName.nullable.error,user.firstName.nullable.error.com.srisris.wr.User.firstName,user.firstName.nullable.error.firstName,user.firstName.nullable.error.java.lang.String,user.firstName.nullable.error,com.srisris.wr.User.firstName.nullable.com.srisris.wr.User.firstName,com.srisris.wr.User.firstName.nullable.firstName,com.srisris.wr.User.firstName.nullable.java.lang.String,com.srisris.wr.User.firstName.nullable,user.firstName.nullable.com.srisris.wr.User.firstName,user.firstName.nullable.firstName,user.firstName.nullable.java.lang.String,user.firstName.nullable,nullable.com.srisris.wr.User.firstName,nullable.firstName,nullable.java.lang.String,nullable]; arguments [firstName,class com.srisris.wr.User]; default message [Property [{0}] of class [{1}] cannot be null]Field error in object 'com.srisris.wr.User' on field 'lastName': rejected value [null]; codes [com.srisris.wr.User.lastName.nullable.error.com.srisris.wr.User.lastName,com.srisris.wr.User.lastName.nullable.error.lastName,com.srisris.wr.User.lastName.nullable.error.java.lang.String,com.srisris.wr.User.lastName.nullable.error,user.lastName.nullable.error.com.srisris.wr.User.lastName,user.lastName.nullable.error.lastName,user.lastName.nullable.error.java.lang.String,user.lastName.nullable.error,com.srisris.wr.User.lastName.nullable.com.srisris.wr.User.lastName,com.srisris.wr.User.lastName.nullable.lastName,com.srisris.wr.User.lastName.nullable.java.lang.String,com.srisris.wr.User.lastName.nullable,user.lastName.nullable.com.srisris.wr.User.lastName,user.lastName.nullable.lastName,user.lastName.nullable.java.lang.String,user.lastName.nullable,nullable.com.srisris.wr.User.lastName,nullable.lastName,nullable.java.lang.String,nullable]; arguments [lastName,class com.srisris.wr.User]; default message [Property [{0}] of class [{1}] cannot be null]Field error in object 'com.srisris.wr.User' on field 'password': rejected value [null]; codes [com.srisris.wr.User.password.nullable.error.com.srisris.wr.User.password,com.srisris.wr.User.password.nullable.error.password,com.srisris.wr.User.password.nullable.error.java.lang.String,com.srisris.wr.User.password.nullable.error,user.password.nullable.error.com.srisris.wr.User.password,user.password.nullable.error.password,user.password.nullable.error.java.lang.String,user.password.nullable.error,com.srisris.wr.User.password.nullable.com.srisris.wr.User.password,com.srisris.wr.User.password.nullable.password,com.srisris.wr.User.password.nullable.java.lang.String,com.srisris.wr.User.password.nullable,user.password.nullable.com.srisris.wr.User.password,user.password.nullable.password,user.password.nullable.java.lang.String,user.password.nullable,nullable.com.srisris.wr.User.password,nullable.password,nullable.java.lang.String,nullable]; arguments [password,class com.srisris.wr.User]; default message [Property [{0}] of class [{1}] cannot be null]Field error in object 'com.srisris.wr.User' on field 'userName': rejected value [null]; codes [com.srisris.wr.User.userName.nullable.error.com.srisris.wr.User.userName,com.srisris.wr.User.userName.nullable.error.userName,com.srisris.wr.User.userName.nullable.error.java.lang.String,com.srisris.wr.User.userName.nullable.error,user.userName.nullable.error.com.srisris.wr.User.userName,user.userName.nullable.error.开发者_StackOverflow中文版userName,user.userName.nullable.error.java.lang.String,user.userName.nullable.error,com.srisris.wr.User.userName.nullable.com.srisris.wr.User.userName,com.srisris.wr.User.userName.nullable.userName,com.srisris.wr.User.userName.nullable.java.lang.String,com.srisris.wr.User.userName.nullable,user.userName.nullable.com.srisris.wr.User.userName,user.userName.nullable.userName,user.userName.nullable.java.lang.String,user.userName.nullable,nullable.com.srisris.wr.User.userName,nullable.userName,nullable.java.lang.String,nullable]; arguments [userName,class com.srisris.wr.User]; default message [Property [{0}] of class [{1}] cannot be null]
My domain classes
package com.srisris.wr
class User {
String userName
String password
//String passwordConfirm
String firstName
String lastName
String email
static mapping = {
tablePerHierarchy false
}
static constraints = {
}
}
package com.srisris.wr
class Representative extends User{
static belongsTo = [ company: Company ]
String jobTitle
String telephone
String fax
static constraints = {
}
}
package com.srisris.wr
class Employer extends User {
Address address
static constraints = {
}
}
package com.srisris.wr
class Employee extends User{
Address address
static constraints = {
}
}
package com.srisris.wr
class Company {
String companyName
Address address
String companyRegistration
int totalEmployeeStrength
int numberOfUkPAYEEmployees
String category
Representative representative
Bank bank
static constraints = {
}
}
package com.srisris.wr
class Bank {
static belongsTo = [ company: Company ]
// static belongsTo = [ retailer: Retailer ]
Company company
static constraints = {
}
}
package com.srisris.wr
class Address {
static belongsTo = [ user: User,company: Company ]
//static belongsTo = [ company: Company]
User user
String address1
String address2
String city
//String state
String county
String zipcode
Company company
static constraints = {
}
}
My Controller
package com.srisris.wr.register.employer import com.srisris.wr.User
class EmployerRegistrationController {
def index = { }
def register={
render params
User user= new User(params)
user.save()
if(user.hasErrors()){
user.errors.allErrors.each {
render it
}
}
}
}
My GSP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head>
<title>Workriders - Employer Registration page - JustProto</title>
</head>
<body>
<g:form action="register" method="post" >
<table width="80%" height="60%" align="left">
<tr><th align="right"><g:message code="Your Company Name"/></th><td><g:textField name="company.companyName"></g:textField></td></tr>
<tr><th align="right"><g:message code="Address"/></th> <td><g:textField name="address.address1" ></g:textField></td></tr><tr><td> </td><td><g:textField name="address.address2"></g:textField></td></tr>
<tr><th align="right"><g:message code="Town/City"/></th><td><g:textField name="address.city" ></g:textField></td></tr>
<tr><th align="right"><g:message code="County"/></th><td><g:textField name="address.county" ></g:textField></td></tr>
<tr><th align="right"><g:message code="PostCode"/></th><td><g:textField name="address.zipcode" ></g:textField></td></tr>
<tr><th align="right"><g:message code="First Name"/></th><td align="left"><g:textField name="user.firstName"></g:textField></td></tr>
<tr><th align="right"><g:message code="Last Name"/></th><td><g:textField name="user.lastName"></g:textField></td></tr>
<tr><th align="right"><g:message code="Telephone"/></th> <td><g:textField name="representative.telephone" ></g:textField></td></tr>
<tr><th align="right"><g:message code="Fax"/></th><td><g:textField name="representative.fax" ></g:textField></td></tr>
<tr><th align="right"><g:message code="Email"/></th><td><g:textField name="user.email" ></g:textField></td></tr>
<tr><th align="right"><g:message code="User Name"/></th><td><g:textField name="user.userName"></g:textField></td></tr>
<tr><th align="right"><g:message code="password"/></th><td><g:passwordField name="user.password" ></g:passwordField></td></tr>
<tr><td> </td><td> <g:submitButton name="create" value="Create"/></td></tr>
</table>
</div>
</g:form>
</body>
</html>
As the stacktrace point out, that error happens because the email
field of user is null.
It means User user= new User(params)
fails. That's because you give the wrong parameters to initialize a User, for example, "User class" does not have "address" property. You should new Employer()
instead.
GORM set nullable: false
as a default constraint for each field of a domain. So when you save a row in the domain, because of nullable:false
you given error will uccor. To solve this problem, one way is to set nullable:true
as a default constraint of GORM. You can set this in your Config.groovy
grails.gorm.default.constraints = { '*'(nullable:true, blank:true) }
When u need to set nullable:true
for any field u will set it in the domain class manually.
精彩评论