Für das <select><option selected="selected">
Problem, ich habe ich beschlossen, nicht ein bisschen verboseness dagegen hätte, wenn es nur eine zeit verboseness ist ... so dass ich einen Tag Dokument erstellt (.tagx) in /WEB-INF/tags/select.tagx
etwa 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>
und es verwenden, etwa 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, bin ich nicht einverstanden, dass dieses hässliche ist ... vielleicht ärgerlich, aber ich bin eigentlich Ich war froh, dass ich nicht musste richte irgendeinen Code dafür ein. Sobald Sie das Tag definiert haben, werden Ihre JSPXs viel aufgeräumter. Außerdem glaube ich einfach nicht, dass es eine Abkürzung dafür gibt.
Nizza antwort, schade, dass es hier nicht funktioniert. Welche Version von jspx macht das für Sie? Sind Sie sicher, dass dies nicht jsp ist? – krosenvold
Sorry, es ist in der Tat JSP; Ich habe sie gekreuzt. Ich nehme an, dass Ihr Weg der einzige ist, der dann anwendbar ist; c: wenn auch in diesem Fall nicht funktionieren wird. – ChssPly76