开发者

Display sub-property in table tag (Spring Roo supplied tag library)

I am using Spring Roo. There is table:table and table:column tags.

How to display sub-p开发者_如何学运维roperty of colections elements in table?

In straightforward way it doesnt work:

<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>

Exception:

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


I modified table.tagx so it could be used with sub-properties and Spring converting capabilities.

<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>


Edit PROJECT/src/main/webapp/WEB-INF/tags/form/fields/table.tagx. At line 78, you should see <c:set var="columnDatePattern" value="${patterns[num.count-1]}" />. Put under that line, the following piece of code:

<!-- 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. -->

Don't forget to change from "item[column]" into "prop". For example, the changed lines should be:

<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>


You can edit entity file Concepts.java :

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

After , you edit to:

<table:column id="c_domain_Concept_translations" property="DefaultTranslationName"  z="user-managed" />

Hope can help you !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜