<table>
<c:if test="${output.list == nul}">
<tr><td><input type="text" /><select></select><input type="text" />
</td>
</tr>
</c:if>
<c:forEach var="iter" items="${output.list}">
<tr><td><input type="text" /><select></select><input type="text" value="${iter.getVal()}" />
</td>
</tr>
</c:forEach>
</tbody>
</table>
If my ${list}
is empty,how can I display .clone
row without duplicating codes or using javascript?
I do not know whether I understood your problem. If you want output one row with all content, when list is empty, try next approach:
<table>
<c:forEach var="i" begin="0" end="${not empty list?(fn:length(list)-1):0}">
<tr class="clone">
<td>
<input type="text" />
<select></select>
<input type="text" value="${list[i]!=null?list[i].getVal():''}" />
</td>
</tr>
</c:forEach>
</tbody>
For use fn:
namespace just add in begin of your file <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Udate: changed according question changes
If the list is empty then add an empty value to the list. You can do it in the servlet or JSP but in JSP you have to write additional java code to modify the list.
<table>
<c:set var="list" value="${output.list}"/>
<c:if test="${empty list && list != null}">
${list.add(null)}
</c:if>
<c:forEach var="iter" items="${list}">
<tr><td><input type="text" /><select></select><input type="text" value="${iter.getVal()}" />
</td>
</tr>
</c:forEach>
</tbody>
</table>
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