• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

display a hyperlink into a comment

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://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.
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you !
It works :)
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :-) )
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic