Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display a hyperlink into a comment

 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.coderanch.com 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 !

Angy.
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Cesar
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you !
It works :)
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Fabian Angy
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.myurl.com xxx
=> xxx < a href="http://www.myurl.com">http://www.myurl.com< a> xxx


And that works :-)

(sorry, I'm writing < a> because the tag without space is interpreted in the message :-) )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic