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

发布于 2024-09-15 10:09:38 字数 572 浏览 3 评论 0原文

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

如何在表中显示集合元素的子属性?

以简单的方式它不起作用:

<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

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

How to display sub-property 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑叹一世浮沉 2024-09-22 10:09:38

我修改了 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>

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>

尘曦 2024-09-22 10:09:38

编辑PROJECT/src/main/webapp/WEB-INF/tags/form/fields/table.tagx。在第 78 行,您应该看到 。在该行下放置以下代码:

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

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>
旧话新听 2024-09-22 10:09:38

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

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

之后,您编辑为:

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

希望可以帮助您!

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 !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文