在jsp上的列表中显示嵌套列表的值
我试图使用在jsp上的列表中显示嵌套列表的值,jsp,spring-mvc,foreach,jstl,Jsp,Spring Mvc,Foreach,Jstl,我试图使用c:forEachsyantax在jsp上迭代pojo列表。 现在的问题是列表包含嵌套列表,所以我应该如何在jsp上显示该特定值 以下是我在jsp上的代码: <c:forEach items="${capQues.captureQuestionList}" var="captureQuestion" varStatus="status"> <fieldset name="captureQuestionList[${status.index}].languageId
c:forEach
syantax在jsp上迭代pojo列表。
现在的问题是列表包含嵌套列表,所以我应该如何在jsp上显示该特定值
以下是我在jsp上的代码:
<c:forEach items="${capQues.captureQuestionList}" var="captureQuestion" varStatus="status">
<fieldset name="captureQuestionList[${status.index}].languageId" value="1">
<legend><c:out value="${captureQuestion.languages}" /></legend>
<div class="question"><textarea class="textarea" name="captureQuestionList[${status.index}].question" value="question"></textarea></div>
</fieldset>
</c:forEach>
其中语言也是captureQuestionList
中的一个列表
提前谢谢我想你这里缺少的是
var
的要点。在第一个循环中,captureQuestion
将是来自列表captureQuestionList
的当前对象。您可以按原样使用该引用,因此不需要使用captureQuestionList[${status.index}]
来获取对象。顺便说一下,正确的语法应该是${captureQuestionList[status.index]}
。因此,字段集名称可以是${captureQuestion.languageId}
For循环只能嵌套。例如(对您的问题对象进行一些假设):
如果要显示单一语言,请添加c:If
以检查该语言
<c:forEach items="${captureQuestion.languages}" var="language">
<c:if test="${language.id eq captureQuestion.questionId}">
<c:out value="${language.name}" />
<c:if>
</c:forEach>
虽然在您的模型中添加对正确语言的引用会更好,这样您就可以使用
${captureQuestion.language}
您好,谢谢您的回复,但我面临的问题是我想取消一种语言的名称,在captureQuestion中的名为language的列表中…简而言之,我的意思是captureQuestion包含语言列表,languages list包含语言名称,,,那么我应该如何打印语言名称呢。非常感谢您的帮助。嗨,Japser thnks,谢谢您的及时回复。正如您所说,它工作正常。非常感谢您的帮助。
<c:forEach items="${capQues.captureQuestionList}" var="captureQuestion">
<fieldset name="${captureQuestion.languageId}">
<legend>
<c:forEach items="${captureQuestion.languages}" var="language">
<c:out value="${language.name}" />
</c:forEach>
</legend>
<div class="question">
<textarea class="textarea" name="${captureQuestion.question}"></textarea>
</div>
</fieldset>
</c:forEach>
<c:forEach items="${captureQuestion.languages}" var="language">
<c:if test="${language.id eq captureQuestion.questionId}">
<c:out value="${language.name}" />
<c:if>
</c:forEach>