【问题标题】:tagx files: c:set tag, access to a property of an objecttagx 文件:c:set 标记,访问对象的属性
【发布时间】:2013-01-30 09:25:14
【问题描述】:

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

的值

有可能吗?

提前谢谢...

【问题讨论】:

    标签: spring spring-roo jsp-tags


    【解决方案1】:

    可以使用命名空间xmlns:spring="http://www.springframework.org/tags" 中的spring:eval 标记。试试这个:

    <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].${..}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-07
      • 2021-03-05
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多