我希望在下拉列表中的页面加载时默认值为空白 这是我的jsp代码:
<div class="ukjentFodselDato ${saksdetaljerForm.sak.personUnderVerge.ukjentFodselsDato ? '':'hidden'}">
<label class="boldText"><spring:message code="common.label.fodsel.ar"/></label>
<input type="hidden" value="${sak.personUnderVerge.fodselAr}" />
<form:select path="sak.personUnderVerge.fodselAr">
<form:options items="${yearList}" />
</form:select>
</div>
java代码:
public static List<Integer> getYears(int range) {
int year = LocalDate.now().getYear();
List<Integer> years = new ArrayList<>();
for(int counter=0; counter < range; counter++) {
years.add(year);
year = year-1;
}
return years;
}
答案 0 :(得分:0)
<div class="ukjentFodselDato ${saksdetaljerForm.sak.personUnderVerge.ukjentFodselsDato ? '':'hidden'}">
<label class="boldText"><spring:message code="common.label.fodsel.ar"/></label>
<input type="hidden" value="${sak.personUnderVerge.fodselAr}" />
<form:select path="sak.personUnderVerge.fodselAr">
<form:option value="" selected="${sak.personUnderVerge.fodselAr == null ? 'selected' : ''}" />
<c:forEach var="year" items="${yearList}">
<form:option value="${year}" selected="${parorende.fodselAr == year ? 'selected' : ''}" >${year}</form:option>
</c:forEach>
</form:select>
</div>