How do I save a composite field value in Grails GSP?

…衆ロ難τιáo~ 提交于 2019-12-07 02:00:33

What I do is generate-all for the House Domain then copy and paste the GSP code and remove the files once I am done. I have also found it smarter to create templates to edit the House domain in the case where I am using the House domain later on.

For you GSP you need something like this (Notice the name attribute)

<tr class="prop">
 <td valign="top" class="name">
   <label for="forSale.numBedrooms"><g:message code="house.numBedrooms.label" default="Num Bedrooms" /></label>
 </td>
 <td valign="top" class="value ${hasErrors(bean: personInstance.forSale, field: 'numBedrooms', 'errors')}">
     <g:select name="forSale.numBedrooms" value="${fieldValue(bean: personInstance.forSale, field: 'numBedrooms')}" 
          noSelection="${['null':'Select a number...']}"
      from="${1..6}"
     />
 </td>
</tr>

In your param string you need *forSale*.numBedrooms=2. this code will work with person.properties = params or new Person(params).

The embedded "instruction" only tells Hibernate to include the parameters in the same table they are still seperate Domain classes. It will probably generate a table for the domain even though you may never use it.

Hope this helps.

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