JSP / EL 的省略号(缩写文本)
我想知道使用 JSP/表达式语言实现省略号缩写的最佳方法是什么。
现在,我一直在使用 fn:substring,这没问题,但我想要三个点“...”,以防文本被截断。
通过网络搜索,我发现 Java Web Parts 有一个 AbbreviateTag。但是我想知道是否有更好的库,或者我是否更好地滚动自己的自定义标签。你有什么建议?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MMBase 标签库有一个支持省略号的 标签。
然而,实现你自己的可能是一个不错的选择......具体取决于你期望省略号如何工作。
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.
由于我无法理解如何使用 mmbase,因此我构建了自己的自定义标签来扩展 SimpleTagSupport。
它的工作方式如下:
输出:
我还在我的博客上记录了 自定义标记实现。这是我的第一个自定义标签,如果有什么可以做得更好,我很高兴收到您的来信。
Since I couldn't understand how to use mmbase, I built my own custom tag extending SimpleTagSupport.
It works in this way:
Output:
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.
旧线程,但我将其发布给任何寻找答案的人。下面是我处理这个问题的方法。该代码位于创建 td 元素的循环内,因此引用了列。如果文本需要截断,我会调整子字符串,为省略号留出空间,然后附加省略号。
Old thread, but I am posting this for anyone searching for an answer. Below is how I handled this. The code was inside a loop creating td elements, hence the reference to columns. If the text needs truncation I adjusted the substring allowing room for the ellipsis and then appended the ellipsis.