Checking flag via jstl

I have the following problem: when I put some data in the model, I want some checkboxes that are equal to the field names in my object to be checked in the overview part. here is the html code:

<div class="myDiv"> <div class="divClass"> <input type="checkbox" name="someData" value="0" id="id1"> <label for="id1">Field1</label> </div> <div class="divClass"> <input type="checkbox" name="someData" value="1" id="id2"> <label for="id2">Field2</label> </div> <div class="divClass"> <input type="checkbox" name="someData" value="2" id="id3"> <label for="id3">Field3</label> </div> <div class="divClass"> <input type="checkbox" name="someData" value="3" id="id4"> <label for="id4">Field4</label> </div> </div> 

and here is the jstl pseudo_code I want to get:

 <c:forEach var="field" items="${list.fields}"> <c:if test="${field.name=='FIELD(1-4)'}">CHECK_THE_APPROPRIATE_CHECKBOX </c:if> </c:forEach> 
+4
source share
2 answers

To check, the checkbox must have its checked attribute set (for "checked" when using XHTML). So the code might look something like this:

 <input type="checkbox" name="someData" value="2" id="id3" <c:if test="${field.name == 'FIELD3'}">checked="checked"</c:if> /> 
+10
source

jstl pseudo_code For checkbox

 <c:set var="someData" value="${paramValues.someData}"></c:set> <c:forEach var="i" items="${someData}"> <c:set var="x" value="${x}${i},"></c:set> <br> </c:forEach> <c:forTokens items="${x}" delims="," var="i" >`enter code here` <c:out value="Value : ${i }"></c:out> </c:forTokens> 
-2
source

Source: https://habr.com/ru/post/1442468/


All Articles