识别h:outputText中的链接 [英] Recognize links in h:outputText
问题描述
我需要使用< h:outputText>
标签组件显示一些文本。有这样的要求,如果文本包含一个URL,即 http // example.com.co
,我需要显示它作为链接。
I need to show some text using <h:outputText>
tag component. There is this requirement that if the text contains an URLs i.e. http//example.com.co
, I need show it as a link.
例如,如果用户输入 Yo quiero www.google.com ,我需要显示 Yo quiero www.google.com
For example, if user enters Yo quiero www.google.com I need to show Yo quiero www.google.com
推荐答案
在您的字符串上进行正则表达式替换。你可以使用 string.replaceAll()
来实现这个功能。
You need a function which does a regular expression replace on your string. You can use string.replaceAll()
for this.
您可以创建一个自定义的jsf标签(
You have multiple options to place this function.
- a href =http://jdevelopment.nl/simple-java-based-jsf-custom-component/ =nofollow noreferrer>示例)
- 您可以创建自定义el功能(示例)
- You can create a method in your backing bean.
- You can create a custom jsf tag (example)
- You can create a custom el function (example)
没有1是最简单的实施imho。
No 1 is the easiest to implement imho.
这篇关于识别h:outputText中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!