当outputdata列表为空时简化默认显示一行
Simplify default display one row when outputdata list is empty
<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>
如果我的 ${list}
是空的,如何在不重复代码或不使用 javascript 的情况下显示 .clone
行?
不知道我是否理解了你的问题。如果你想输出一行包含所有内容,当列表为空时,尝试下一种方法:
<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>
要使用 fn:
命名空间,只需在文件开头添加 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Udate: 根据问题变化
如果列表为空,则向列表中添加一个空值。您可以在 servlet 或 JSP 中执行此操作,但在 JSP 中,您必须编写额外的 java 代码来修改列表。
<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>
<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>
如果我的 ${list}
是空的,如何在不重复代码或不使用 javascript 的情况下显示 .clone
行?
不知道我是否理解了你的问题。如果你想输出一行包含所有内容,当列表为空时,尝试下一种方法:
<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>
要使用 fn:
命名空间,只需在文件开头添加 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Udate: 根据问题变化
如果列表为空,则向列表中添加一个空值。您可以在 servlet 或 JSP 中执行此操作,但在 JSP 中,您必须编写额外的 java 代码来修改列表。
<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>