使用 Grails Fields 插件,您可以编写更短、更干净、更干的代码:
<bean:withBean beanName="person">
<bean:field property="username" label="Login Name:"/>
<bean:field property="userRealName" label="Full Name:"/> >
</bean:withBean>
上面的代码将与以下代码相同:
<tr class="prop">
<td valign="top" class="name"><label for="username">Login Name:</label></td>
<td valign="top" class="value ${hasErrors(bean: person, field: 'username', 'errors')}">
<input type="text" id="username" name="username" value="${person.username?.encodeAsHTML()}"/>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name"><label for="userRealName">Full Name:</label></td>
<td valign="top" class="value ${hasErrors(bean: person, field: 'userRealName', 'errors')}">
<input type="text" id="userRealName" name="userRealName" value="${person.userRealName?.encodeAsHTML()}"/>
</td>
</tr>
但是,我必须手动更改所有已经编写的代码吗?