我必须在Grails中编写一个更新或更改用户数据表单。这是我的表格:
<g:form class="form-signin" controller="VisitorSpace">
<label for="login" class="sr-only">Login</label>
<g:textField id="login" class="form-control" name="login" placeholder="login" required="" autofocus=""/>
<label for="firstName" class="sr-only">Your name</label>
<g:textField id="firstName" class="form-control" name="firstName" placeholder="Your name" required="" type="text"/>
<label for="lastName" class="sr-only">Your lastname</label>
<g:textField id="lastName" class="form-control" name="lastName" placeholder="Your lastname" required="" type="text"/>
<label for="inputEmail" class="sr-only">e-mail</label>
<g:textField id="inputEmail" class="form-control" name="email" placeholder="e-mail" required="" autofocus="" data-translatable-string="Email address" type="email"/>
<label for="inputPassword" class="sr-only">Password</label>
<g:passwordField id="inputPassword" class="form-control" name="password" placeholder="Password" required="" data-translatable-string="Password"/>
<label for="confirmPassword" class="sr-only">Confirm password</label>
<g:passwordField id="confirmPassword" class="form-control" name="controlPassword" placeholder="Confirm password" required="" data-translatable-string="Password"/>
<g:actionSubmit value="Commit change" action="updateUserData" class="btn btn-lg btn-primary btn-block">Commit change</g:actionSubmit>
</g:form>
旧数据必须显示在字段中,因此必须从数据库发送到加载视图表单的时刻。我知道,调用所需的控制器方法可以做到这一点,并且必须在加载视图窗体之前或期间调用这样的方法。但是如何做到这一点呢?
将value
属性添加到您的输入字段元素中,并使用您想要的来自控制器的当前数据。这就是你想要的吗?
<g:textField id="lastName" value="${objectInstance.lastName}" ... />