我使用Spring,并且更改了list.tagx文件以在顶部添加一个标题。此标题是第一项的属性值。问题是,我希望以通用的方式指定这个属性,作为list.tagx的一个属性。就像这样:
<jsp:directive.attribute name="titleValue" type="java.lang.String"
required="false" rtexprvalue="true"
description="The value to be shown in the title" />
...
<c:when test="${not empty items}">
<c:if test="${not empty titleValue}">
<c:set var="variable" value="${items[0].titleValue}" />
</c:if>
...存在一个问题,因为它试图将名为“titleValue”的属性的值输入到对象项中。例如,如果我将'titleValue‘的值设置为'firstName',那么我希望得到titleValue的值
有可能这样做吗?
提前谢谢..。
发布于 2013-01-30 14:55:52
通过使用名称空间xmlns:spring="http://www.springframework.org/tags"中的xmlns:spring="http://www.springframework.org/tags"标记是可能的。试试这个:
<jsp:directive.attribute name="titleValue" type="java.lang.String"
required="false" rtexprvalue="true"
description="The value to be shown in the title" />
...
<c:when test="${not empty items}">
<c:if test="${not empty titleValue}">
<c:set var="variable">
<spring:eval expression="items[0].${titleValue}" />
</c:set>
</c:if>
...编辑:修正了错误,对不起。不是${items[0]}.${..}而是items[0].${..}
https://stackoverflow.com/questions/14600482
复制相似问题