【发布时间】:2015-03-06 18:51:24
【问题描述】:
我有以下问题
- 我正在创建一个
List<UserProfileHelper>的值 - 此列表添加到 ProfileUserCommand 以发送到视图 (profile.gsp) 进行渲染
如您所见,ProfileUserCommand 对象包含 2 个布尔值,用于控制 GSP 中复选框的状态。这部分工作完美,因为我可以看到 GSP 正确呈现,并且复选框正确标记/未标记。
当将表单提交回控制器时,我不知道如何使用来自 GSP 的更新值“重建”此列表,因此我可以获得更新数据的 List<UserProfileHelper>。
这是我的课
UserProfileHelper.groovy
class UserProfileHelper {
Long optionId
String optionName
boolean isSubMenu
boolean hasAccess
boolean canWrite
}
ProfileUserCommand.groovy
class ProfileUserCommand {
String username
List userProfile = [].withLazyDefault { return new UserProfileHelper() }
static constraints = {
username blank: false
userProfile blank: true, nullable: true
access blank: true, nullable: true
}
}
profile.gsp(仅 GSP 的相关部分)
<g:each in="${command.userProfile}" var="option">
<tr>
<td>
${option.optionId}
</td>
<td>
<g:if test="${!option.isSubMenu}">
${option.optionName}
</g:if>
<g:else>
</g:else>
</td>
<td>
<g:if test="${option.isSubMenu}">
${option.optionName}
</g:if>
<g:else>
</g:else>
</td>
<td>
<g:checkBox bean="${option}" name="access" value="${option.hasAccess}"/>
</td>
<td>
<g:checkBox bean="${option}" name="write" value="${option.canWrite}"/>
</td>
</tr>
</g:each>
提前致谢!
【问题讨论】: