我必须在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>
旧数据必须显示在字段中,因此必须从数据库发送到加载视图表单的那一刻。我知道,有可能调用所需的控制器方法来执行此操作,并且必须在加载视图表单之前或之后调用此方法。但是怎么做呢?
答案 0 :(得分:1)
使用您希望从控制器获取的当前数据将value
属性添加到输入字段元素。那是你要的吗?
<g:textField id="lastName" value="${objectInstance.lastName}" ... />