Hi
I have simple test example with the following domain.
class Client {
LTitle ltitle
String firstname
String surname
Date dateCreated
Date lastUpdated
String updatedBy
static constraints = {
}
} // end Client
class LTitle {
int titleId
String title
static constraints = {
title blank: false, nullable: false
}
}
in gsp
<div class="fieldcontain ${hasErrors(bean: clientInstance, field: 'title', 'error')} required">
<label for="title">
<g:message code="client.title.label" default="Title" />
<span class="required-indicator">*</span>
</label>
<g:select id="titleId" name="titleId"
from="${uk.co.lbl.comman.LTitle.list().sort{ it.title }}"
optionKey="id" optionValue="title"
required="" value="${clientInstance?.ltitle?.id}"
class="many-to-one"/>
</div>
Controller
def create() {
respond new Client(params)
}
@Transactional
def save(Client clientInstance) {
if (clientInstance == null) {
notFound()
return
}
if (clientInstance.hasErrors()) {
respond clientInstance.errors, view:'create'
return
}
clientInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'client.label', default: 'Client'), clientInstance.id])
redirect clientInstance
}
'*' { respond clientInstance, [status: CREATED] }
}
}
When I try to save form data. I am getting following error
Property [ltitle] of class [class uk.co.lbl.client.Client] cannot be null
Please can some one advice me.
thanks
ish
I have simple test example with the following domain.
class Client {
LTitle ltitle
String firstname
String surname
Date dateCreated
Date lastUpdated
String updatedBy
static constraints = {
}
} // end Client
class LTitle {
int titleId
String title
static constraints = {
title blank: false, nullable: false
}
}
in gsp
<div class="fieldcontain ${hasErrors(bean: clientInstance, field: 'title', 'error')} required">
<label for="title">
<g:message code="client.title.label" default="Title" />
<span class="required-indicator">*</span>
</label>
<g:select id="titleId" name="titleId"
from="${uk.co.lbl.comman.LTitle.list().sort{ it.title }}"
optionKey="id" optionValue="title"
required="" value="${clientInstance?.ltitle?.id}"
class="many-to-one"/>
</div>
Controller
def create() {
respond new Client(params)
}
@Transactional
def save(Client clientInstance) {
if (clientInstance == null) {
notFound()
return
}
if (clientInstance.hasErrors()) {
respond clientInstance.errors, view:'create'
return
}
clientInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'client.label', default: 'Client'), clientInstance.id])
redirect clientInstance
}
'*' { respond clientInstance, [status: CREATED] }
}
}
When I try to save form data. I am getting following error
Property [ltitle] of class [class uk.co.lbl.client.Client] cannot be null
Please can some one advice me.
thanks
ish