2

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の値を取得します。

それは可能ですか?

前もって感謝します...

4

1 に答える 1

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

于 2013-01-30T14:55:52.190 に答える