I have written this simple jsp page: I want to show a simple list of object (Person), with a label (showing the name of the person) and a checkbox (that shows if the person is at least 18 yo).
I also write the corresponding Java class 'Person', with a String (name) and a boolean (isAdult).
Here is my jsp (personList is a List of Person objects)
<table>
<th>NAME</th>
<th>IS ADULT</th>
<c:forEach var="person" items="${personList}">
<tr>
<td>${person.name}</td>
<td>
<input type="checkbox" value="checked"/>
</td>
</tr>
</c:forEach>
</table>
This portion of code shows me a list in which all checkboxes are not checked (names are correct.
How could I obtain that every checkbox in the list is checked (or not), referring to the boolean attribute 'isAdult' of the Person object?
You can use EL ternary operator like this:
<input type="checkbox" ${person.adult ? 'checked' : ''}>
${person.adult} will invoke isAdult method that encapsulating adult attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With