grails multiple select: values are not stored in related object

孤人 提交于 2019-12-02 15:28:35

问题


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?


回答1:


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)
}


来源:https://stackoverflow.com/questions/20921407/grails-multiple-select-values-are-not-stored-in-related-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!