'condition <c:when test=""> within jstl <c:forEach>
beforehand I have model.addattribute(list, 'list') in which list is a list of VOs Within each VO I have choices=[val1,val2,val3...] and in some VOs I have choices=[]
I want to make a code in which:
- if choice doesn't have values: text type input appears
- and when it has values: radio type input appears
no 2. works fine, but I'm having trouble with the condition within my when statement.
<c:when test="${empty ${one.survey_choices}}">
I have also tried
<c:when test="${empty one.survey_choices}">
but both don't work.
Here's my code:
<c:forEach items="${surveyList}" var="one">
<tr>
<td style="text-align: left">
<h4 class="fw-bold text-center mt-3"></h4>
<p class="fw-bold">${one.survey_idx}.${one.survey_question}</p>
<div class="form-check mb-2">
<c:choose>
<c:when test="${empty ${one.survey_choices}}"> <!-- ERROR!!! -->
<p>success!!!</p>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">${one.survey_idx}.${one.survey_question}</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
</c:when>
<c:otherwise>
<c:forTokens items="${one.survey_choices}" var="choice" delims=",">
<input class="form-check-input" type="radio" name="exampleForm" id="radioExample1" />
<label class="form-check-label" for="radioExample1">
<c:out value="${choice}" />
</label>
</c:forTokens>
</c:otherwise>
</c:choose>
</div>
</td>
</tr>
</c:forEach>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
