Search code examples
liferayliferay-6

How to truncate a string in Search Container


I have a string which i am displaying in search container, is there a way we can truncate the string and display it up to a limited length.

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

regards


Solution

  • You can use StringUtil.shorten(String s, int length), to limit the string to desired length.

    When using within search container, make sure to remove property attribute from column-text tag as property attribute will reset value to the original one.