I was wondering what is the best way to implement an ellipsis abbreviation with JSP / Expression Language.
For now, I've been using fn:substring, which is ok, but I would like to have the three dots "...", in case the text was truncated.
With a web search I found that Java Web Parts has an AbbreviateTag. However I was wondering if there are better libraries, or if it's better I roll my own custom tag. What do you suggest?
The MMBase tag library has a tag that supports ellipsis.
However, implementing your own could be a good option ... depending on exactly how you expect the ellipsis to work.
Since I couldn't understand how to use mmbase, I built my own custom tag extending SimpleTagSupport.
It works in this way:
<%@ 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>
Output:
What a beautiful day.
What a bea…
I've also documented the custom tag implementation on my blog. This is my first custom tag, if anything can be done better, I'd be happy to hear from you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With