For the <select><option selected="selected">
problem, I decided I wouldn't mind a bit of verboseness, if it was only one-time-verboseness... so I created a tag document (.tagx) in /WEB-INF/tags/select.tagx
like so:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:directive.attribute name="id" required="true" />
<jsp:directive.attribute name="name" required="true" />
<jsp:directive.attribute name="options" required="true" />
<jsp:directive.attribute name="selected" required="true" />
<select id="${id}" name="${name}">
<c:forEach var="opt" items="${options}">
<c:choose>
<c:when test="${opt == selected}"><option selected="selected">${opt}</option></c:when>
<c:otherwise><option>${opt}</option></c:otherwise>
</c:choose>
</c:forEach>
</select>
</jsp:root>
and use it like so:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml" version="2.1"
...
xmlns:form="urn:jsptagdir:/WEB-INF/tags/">
...
<head>
...
</head>
<body>
<form method="POST" commandName="loginRequest" action="index_login.html">
<fieldset id="loginFieldSet">
...
<div>
<label for="day" path="day">Favourite day: </label>
<form:select id="day" name="day" selected="Saturday"
options="Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" />
</div>
</fieldset>
<div>
<input type="submit" tabindex="3" />
<input type="reset" tabindex="4" />
</div>
</form>
</body>
</html>
krosenvold, I don't agree that this is ugly... maybe annoying but I'm actually glad I didn't have to write any code for this. Once you've defined the tag, your JSPXs become much tidier. Besides, I simply don't think there is a short cut for this.