my dog learned polymorphism
The moose likes JSF and the fly likes display a hyperlink into a comment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "display a hyperlink into a comment" Watch "display a hyperlink into a comment" New topic

display a hyperlink into a comment

Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
Hi !

I have a problem to display a hyperlink into a comment.
I need to retrieve some comments from my database to show them in a panel. But, if there is a link into a comment, I have to show this link in blue underlined and not the entire comment.

Example: Please visite if you need help.

How can I achieve this? Which tag should I use?

<h:outputLink> exists but the whole comment is a hyperlink with this tag and not just a part.

Thanks in advance !


Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Fabian. If the property comment contains a plain html hyperlink with the <a> tag withing the property you must use a ouputText tag but with the property escape="false" to render the <a> tag.

Otherwise in your managed bean you can use regular expressions to find the http links and format it withing a <a> tag.
A better solution could be to parse the comment string, find the http links add it to a list and use a <ui:repeat> to show the command links.
I hope this will help you
Kind regards

When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

Well Hi,

I think if there's an <a> tag in the comment ... you might also use some css ... can't we here. Just give it a try.

cheers :thumbup:
Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
Thank you !
It works :)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

To be more concise: if you have displayable data that contains HTML, use the outputText "escape="false"" attribute to present the HTML in its native form (without escapes).

Having said that, I do NOT recommend a general policy of building raw HTML in the backing bean. I've seen what happens when people do that, and it's pretty ugly, and not just when you're doing it in JSF.

So keep the "punch-through" HTML to a minimum. Stuff like database fields with (non-JSF) hyperlinks or "message of the day" formatted text blocks, not as an excuse for meddling with general page layout.

An IDE is no substitute for an Intelligent Developer.
Fabian Angy
Ranch Hand

Joined: Oct 27, 2008
Posts: 90
I used "escape=false" with a converter

And in my converter, I take the comment and I use a regex to find an URL in the comment and I put the url between a < a> tag.
=> xxx xxx
=> xxx < a href="">< a> xxx

And that works :-)

(sorry, I'm writing < a> because the tag without space is interpreted in the message :-) )
I agree. Here's the link:
subject: display a hyperlink into a comment
It's not a secret anymore!