Saturday, January 21, 2017

Dropdown with default value



HTML:
<form:select path="pilihanJawatan" id="idPilihanJawatan" disabled="true" >
<option value="">N/A</option>
<c:forEach items="${pilihanJawatans}" var="jawatan">
<option <c:if test="${jawatan.key eq defaultValue}">selected="selected"</c:if> value="${jawatan.key}">${jawatan.value}
</option>
</c:forEach>
</form:select>

Java Controller:
// Set dropdown list value and text
Map<String,String> pilihanJawatans = new LinkedHashMap<String,String>();
pilihanJawatans.put("CLN", "Calon");
pilihanJawatans.put("PPPPT", "Pegawai Penilai - PPT");
pilihanJawatans.put("PPLPPT", "Pegawai Penilai Luar - PPT");
// Dropdown default value
String defValue = "PPPPT";
mav.addObject("pilihanJawatans", pilihanJawatans);
mav.addObject("defaultValue", defValue);

No comments:

Post a Comment