You named the select tag "receiptItems", so in the Controller inspect that parameter and then add it to the receiptInstance:
params?.receiptItems?.each {
def service = HealthService.get(it)
receiptInstance.addToHealthServices(service)
}
質問
I have a multiple select as follows:
<g:select name="receiptItems" from="${HealthService.findAllByDoctor(Doctor.findBySecUser(new ReceiptController().getCurrentlyLoggedUser()))}"
multiple="multiple" optionKey="id"
optionValue="${{it.healthServiceType.healthService}}"
size="5" value="${receiptInstance?.healthServices*.id}" class="many-to-many"
onchange="${remoteFunction(
controller: 'Receipt',
action: 'sumReceiptItems',
params: '\'receiptItemsSelected=\' + jQuery(this).val()',
onSuccess: 'updateTotalAmount(\'totalAmount\', data, \'00000\')')}"/>
After each selection, with the remoteFunction
, a method from controller is called to do some calculation and update the totalAmount field. It works well but, when save
method is called, healthServices
field is null...and I don't understand why.
I've tried also with
receiptInstance?.healthServices.collect{it.id}
but I have the same result. Any suggestion?
解決
You named the select tag "receiptItems", so in the Controller inspect that parameter and then add it to the receiptInstance:
params?.receiptItems?.each {
def service = HealthService.get(it)
receiptInstance.addToHealthServices(service)
}