I'm having trouble getting auto value from DB and making auto value checked in the page edit page
here the JSP
<c:if test="${l.code == 'USER_NOT_BLOCK' }">
<td>
<select class="selectpicker" id="value-${l.code}" name="value-${l.code}" multiple="multiple">
<c:forEach items="${listUser}" var="list">
<option value="${list}" >${list}</option>
</c:forEach>
</select>
</td>
</c:if>
and this one the controller
public ModelAndView addPref(@RequestParam String code) throws Exception{
ModelAndView mv=null;
List<SystemParameter> list = null;
String listUser = "";
try {
mv = new ModelAndView("page.pref.add");
list = this.sysParamService.getPreferenceDetail(code);
listUser = this.userService.getUsername();
System.out.println(listUser.toString());
mv.addObject("list", list);
mv.addObject("listUser", listUser); //this is the dropdown value
mv.addObject("code", code);
}
catch(Exception e){
LOG.error("Exception at addPref()", e);
}
finally{
list = null;
}
I am open to all your suggestions, even using javascript is not a problem
The generic pattern to select a value in a list with JSP is
<c:set var="list" value="${fn:split('ONE,TWO,THREE,FOUR', ',')}"/>
<c:set var="selectedItem" value="TWO"/>
<select>
<c:forEach items="${list}" var="item">
<option value="${item}" ${item == selectedItem ? 'selected':''}>${item}</option>
</c:forEach>
</select>