在表标记中显示子属性(Spring Roo提供的标记库)

时间:2010-08-20 10:19:40

标签: spring-mvc jsp-tags spring-roo

我正在使用Spring Roo。有table:tabletable:column个标记。

如何在表格中显示colections元素的子属性?

以直截了当的方式,它不起作用:

<table:table data="${knowledgebase.concepts}" id="l_domain_Concept" path="/concepts" z="user-managed">
  <table:column id="c_domain_Concept_translations" property="defaultTranslation.name"  z="user-managed" />
</table:table>

例外:

Caused by: javax.el.PropertyNotFoundException: Property 'defaultTranslation.name' not found on type domain.data.Concept

3 个答案:

答案 0 :(得分:1)

我修改了table.tagx,因此它可以与子属性和Spring转换功能一起使用。

<c:forTokens items="${columnProperties}" delims="," var="column" varStatus="num">
<c:set var="prop" value="${ item }" />
    <c:forTokens items="${column}" delims="." var="subprop">
        <c:set var="prop" value="${ prop[subprop]}" />
    </c:forTokens>
<c:set var="columnMaxLength" value="${lengths[num.count - 1]}" scope="request"/>
 <td>
     <c:choose>
         <c:when test="${not convert}">
             <c:out value="${columnMaxLength lt 0 ? prop : fn:substring(prop, 0, columnMaxLength)}" />
         </c:when>
         <c:otherwise>
             <spring:eval expression="prop" />
     </c:otherwise>
     </c:choose>
 </td>

答案 1 :(得分:0)

修改PROJECT/src/main/webapp/WEB-INF/tags/form/fields/table.tagx。在第78行,您应该看到<c:set var="columnDatePattern" value="${patterns[num.count-1]}" />。放在那一行下面的代码如下:

<!-- Get the last descendant property -->
<c:set var="prop" value="${item}" />
<c:forTokens items="${column}" delims="." var="subprop">
    <c:if test="${not empty prop}">
        <c:set var="prop" value="${prop[subprop]}" />
    </c:if>
</c:forTokens>
<!-- Now under tag c:choose below, please change from "item[column]" into "prop" -->
<!-- // End of Get the last descendant property. -->

不要忘记从"item[column]"更改为"prop"。例如,更改的行应为:

<c:choose>
    <c:when test="${columnType eq 'date'}">
        <spring:escapeBody>
            <fmt:formatDate value="${prop}" pattern="${fn:escapeXml(columnDatePattern)}" var="colTxt" />
        </spring:escapeBody>
    </c:when>
    <c:when test="${columnType eq 'calendar'}">
        <spring:escapeBody>
            <fmt:formatDate value="${prop.time}" pattern="${fn:escapeXml(columnDatePattern)}" var="colTxt"/>
        </spring:escapeBody>
    </c:when>
    <c:otherwise>
        <c:set var="colTxt">
            <spring:eval expression="prop" htmlEscape="false" />
        </c:set>
    </c:otherwise>
</c:choose>

答案 2 :(得分:0)

您可以编辑实体文件Concepts.java:

@Transient
public String getDefaultTranslationName(){
         return defaultTranslation.getName();
}

之后,您编辑为:

<table:column id="c_domain_Concept_translations" property="DefaultTranslationName"  z="user-managed" />
希望可以帮到你!