Code Junkie
Code Junkie

Reputation: 7788

Grails rejected value [null]

I'm getting a validation error during save on field 'adjustmentType': rejected value [null] I'm a little puzzled by this error because I have my mapping set to allow nullables

static mapping = {  
    columns{
        adjustmentType column: 'adjustment_type', length: 10, sqlType:"char", nullable: true
    }
}

The other part I don't understand is why I'm getting an exception rather than a validation message.

I have the following code

<g:hasErrors bean="${recoveryDetailInstance}">
    <ul class="errors" role="alert">
        <g:eachError bean="${recoveryDetailInstance}" var="error">
            <li
                <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                    error="${error}" /></li>
        </g:eachError>
    </ul>
</g:hasErrors>

Controller

@Transactional
def update() {  
    def recoveryDetailInstance = RecoveryDetail.get(new RecoveryDetail(params));


    if (recoveryDetailInstance == null) {
        redirect (uri:'/')
        return
    }

    recoveryDetailInstance.save(flush:true,failOnError:true)

    redirect (controller:"recoveryDetail", action:"edit", params:recoveryDetailInstance.getPK())
}

Upvotes: 0

Views: 2469

Answers (1)

doelleri
doelleri

Reputation: 19682

nullable is a constraint, not a database mapping. It belongs in the constraints block instead.

static constraints = {
    adjustmentType nullable: true
}

Upvotes: 2

Related Questions