我有一个控制器,编辑方法在表单文件中绘制用户信息。但是当我尝试更新错误命令对象返回 userCommand 对象时,我丢失了用户对象的所有信息。
有没有办法以相同的形式使用两者?或者我在这里缺少的东西。
用户控制器类
class UserController {
def edit(User user) {
respond user
}
def update(UserCommand userCommand) {
log.debug "Update a User"
if (userCommand.hasErrors()) {
respond userCommand.errors, view: 'edit'
return
}
}
}
_form.gsp 文件
<g:form action="update">
<div class="form-group">
<label for="firstName">User First Name</label>
<input class="form-control" name="firstName" value="${user?.firstName}">
</div>
<div class="form-group">
<label for="lastName">User Last Name</label>
<input class="form-control" name="lastName" value="${user?.lastName}">
</div>
</g:form>