When using Grails, the GSP code to render each form field looks something like this:
<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>
<tr class="prop">
<td valign="top" class="name"><label for="passwd">Password:</label></td>
<td valign="top" class="value ${hasErrors(bean: person, field: 'passwd', 'errors')}">
<input type="password" id="passwd" name="passwd" value="${person.passwd?.encodeAsHTML()}"/>
</td>
</tr>
Note that almost exactly the same 5 lines of GSP / HTML code are repeated for each form field. This does not seem very dry to me, and I wonder if others have found a better approach?
I found 2 plugins that are trying to solve this problem, a form helper and bean-fields . If anyone has experience using any of them, I would be very interested to hear from them. Alternatively, if there are other solutions / plugins, please let me know.
Thanks. Don
Dónal source
share