[EMAIL PROTECTED] wrote:
Hi,
My application consists of several forms, all following a common style. Each
form is rendered using a table. This results in the following code for each
field:
<tr>
<td> <bean:message key="field.xxx"> </td>
<td>
<html:text property="xxx" readonly="${readonly}" /><br>
<html:errors property="xxx" /><br>
</td>
</tr>
The only variations are the name of the field ("xxx" in the snippet) as well as
the field type (in most cases html:text, sometimes html:checkbox). Is there a
way to reduce this redundant code?
There are lots of ways :-) You didn't list what technologies you're
using, but here are some possibilities:
- if you're using JSP 2.0, you could create a tag file to represent each
type of form field and encapsulate the common markup there
- you could write a JSP Custom Tag to emit the markup (though I don't
recommend that, since altering the markup then involves recompiling)
- if you're using Tiles, you could create a tile definition to
encapsulate the common markup
- if you're using Struts 2, you could create a Struts 2 component / tag
to handle this
- you could use a plain ol' jsp:include tag or @include directive
There are probably other options I'm not thinking of, but any of those
should work fine.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]