xMilos
xMilos

Reputation: 2018

How to generate list of checkboxes by iterating java List?

My Java code,

public ModelAndView getDefault(ModelAndView mav,@RequestParam(value = "QueryCode", 
required = false, defaultValue = "207") String QueryCode) {
    List<String> list=  columnService.getColumnName(QueryCode);
    mav.addObject("columnList",list);
    return mav;
}

I tried something like this in JSP,

<c:set var="jspList" value="${columnList}" />
<%
     for(int i = 0; i < jspList.length; i++){
%>
<input type="checkbox" name="<%= jspList[i]%>"><br/>
<%
     }
%>

but it didn't work and I am getting error like,

cannot resolve symbol jspList.

Upvotes: 0

Views: 611

Answers (1)

Blank
Blank

Reputation: 12378

You can use c:forEach:

<c:forEach items="${columnList}" var="item">
   <input type="checkbox" name="${item}">
</c:forEach>

Upvotes: 2

Related Questions