2

パラメータをレンダリングし、送信したすべてのデータを取得する

["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"]

エラースタック

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.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]

私のドメインクラス

package com.srisris.wr

class User {

    String userName
    String password
    //String passwordConfirm
    String firstName
    String lastName
    String email

    static mapping = {
        tablePerHierarchy false
    }
    static constraints = {

    }
}

パッケージ 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 = {

    }
}

私のコントローラー

パッケージ com.srisris.wr.register.employer インポート 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
            }

        }
    }
}

私の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>&nbsp;</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>&nbsp;</td><td> <g:submitButton name="create" value="Create"/></td></tr>          
        </table>
      </div>
    </g:form>

  </body>

</html>
4

2 に答える 2

2

スタックトレースが指摘するように、emailユーザーのフィールドがnullであるため、そのエラーが発生します。

User user= new User(params)失敗という意味です。これは、ユーザーを初期化するために間違ったパラメーターを指定したためです。たとえば、「ユーザー クラス」には「アドレス」プロパティがありません。new Employer()代わりにすべきです。

于 2011-06-09T08:01:11.937 に答える
0

nullable: falseドメインの各フィールドのデフォルトの制約として設定された GORM 。そのため、ドメインに行を保存すると、nullable:false指定されたエラーが発生します。この問題を解決するにはnullable:true、GORM のデフォルトの制約として設定する方法があります。これは Config.groovy で設定できます

grails.gorm.default.constraints = {
   '*'(nullable:真、空欄:真)
}

nullable:trueフィールドを設定する必要がある場合は、手動でドメイン クラスに設定します。

于 2013-08-31T17:30:41.567 に答える