tagx文件:c:set tag,访问对象的属性

时间:2013-01-30 09:25:15

标签: spring spring-roo jsp-tags

我正在使用Spring Roo,我更改了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'的属性的值获取到对象项[0]中。例如,如果我将'titleValue'的值设置为'firstName',我想获得 items [0] .firstName

的值

有可能吗?

提前致谢...

1 个答案:

答案 0 :(得分:2)

可以使用命名空间spring:eval中的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].${..}