Ellipsis (shortened text) with JSP / EL

I was wondering what is the best way to implement the ellipsis abbreviation with JSP / Expression Language.

I am currently using fn: substring, which is good, but I would like to have three dots "..." if the text was truncated.

Using web search, I found that the Java web part has an AbbreviateTag . However, I was wondering if there are better libraries, or if it is better, I translate my own tag. What are you offering?

+5
source share
3 answers

Since I could not figure out how to use mmbase, I created my own custom tag that extends SimpleTagSupport.

:

<%@ taglib prefix="sti" uri="/WEB-INF/tlds/stivlo.tld" %> 
<p><sti:ellipsis>What a beautiful day.</sti:ellipsis></p>
<p><sti:ellipsis maxLength="10">What a beautiful day.</sti:ellipsis></p>

:

What a beautiful day.
What a bea…

. , - , .

+2

MMBase tag, .

... , , .

+3

, , . . , td-, , . , , , .

<c:if test="${columnMaxLength ge 0}">      
  <c:set value="" var="ellipsis" />           
  <c:if test="${fn:length(colTxt) gt columnMaxLength}">     
    <c:set value="..." var="ellipsis" />    
  </c:if>
  <c:set value="${fn:substring(colTxt, 0, (columnMaxLength - fn:length(ellipsis)))}${ellipsis}" var="colTxt" />
</c:if>
<c:out value="${colTxt}" />
0

All Articles