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.
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
When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
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.
Joined: Oct 27, 2008
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.