This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "display a hyperlink into a comment" Watch "display a hyperlink into a comment" New topic
Author

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 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.


SCJP 5
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
Cesar


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:


http://plainoldjavaobject.blogspot.in
Fabian Angy
Ranch Hand

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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
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 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 :-) )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display a hyperlink into a comment
 
Similar Threads
Dynamic Columns problem in datatable
selectBooleanCheckbox
t:datatable error in tomahwak 1.1.7
Question on how to sort tomahawk datatable
strachable columns in jsf