【问题标题】:How to truncate a string in Search Container如何截断搜索容器中的字符串
【发布时间】:2017-04-24 20:50:03
【问题描述】:

我有一个要在搜索容器中显示的字符串,有没有办法可以截断字符串并将其显示到有限的长度。

<liferay-ui:search-container-row modelVar="alert" className="AlertHeader">
    <liferay-ui:search-container-column-text 
        name="Header Id" property="alertHeaderId" value="<%= String.valueOf(alert.getHeaderId()) %>"/>

    <liferay-ui:search-container-column-text 
        name="Alert Description" property="alertDescription" value="<%= StringUtil.shorten(alert.getDescription(), 20) %>"/>

    <liferay-ui:search-container-column-text 
        name="Start Date" property="startDate" value="<%= String.valueOf(alert.getStartDate()) %>"/>

    <liferay-ui:search-container-column-text 
        name="End Date" property="endDate" value="<%= String.valueOf(alert.getEndDate()) %>"/>

    <liferay-ui:search-container-column-text 
        name="Distribution Type" property="distributionType" value="<%= alert.getDistributionType() %>"/>

</liferay-ui:search-container-row>

问候

【问题讨论】:

  • 您可以使用StringUtil.shorten(String s, int length),将字符串限制为所需的长度。
  • 普拉卡什!我试过&lt;liferay-ui:search-container-column-text name="Description" property="description" value="&lt;%= StringUtil.shorten(alert.getDescription(), 20) %&gt;"/&gt; 但没用。
  • 你能在这个标签外使用这个得到正确的值 StringUtil.shorten(alert.getDescription(), 20) 吗?
  • 是的,我能够得到它。
  • 我认为,它与property 属性有关,您是否尝试将其删除以进行描述?

标签: liferay liferay-6


【解决方案1】:

您可以使用StringUtil.shorten(String s, int length),来限制 字符串到所需的长度。

在搜索容器中使用时,请确保从column-text 标记中删除property 属性,因为属性属性会将值重置为原始值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-04
    • 2014-02-26
    • 2014-12-04
    • 2011-02-16
    • 1970-01-01
    相关资源
    最近更新 更多