Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can encapsulate the <code>mytext</code> into an object (say <code>MyTextTO</code> ) .Then you implement a method (say <code>getLinkifiedMyText()</code>) to return the linkified format of <code>mytext</code> on the <code>MyTextTO</code>. Your MBean should has an <code>ArrayList&lt;MyTextTO&gt;</code>to store a list of the <code>MyTextTO</code> which will be displayed in your JSF using <code>&lt;h:dataTable&gt;</code> . After you bind the value of the <code>&lt;h:outputText&gt;</code> to the <code>getLinkifiedMyText()</code>, the linkified text can be displayed.</p> <p>I refer to <a href="https://stackoverflow.com/questions/5134959/convert-plain-text-to-html-text-in-java">this link</a> to implement the <code>getLinkifiedMyText()</code> :</p> <pre><code>public class MyTextTO{ private String mytext; /**Getters , setters and constructor**/ public String getLinkifiedMyText(){ try { Pattern patt = Pattern.compile("(?i)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()&lt;&gt;]+|\\(([^\\s()&lt;&gt;]+|(\\([^\\s()&lt;&gt;]+\\)))*\\))+(?:\\(([^\\s()&lt;&gt;]+|(\\([^\\s()&lt;&gt;]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'\".,&lt;&gt;???“”‘’]))"); Matcher matcher = patt.matcher(this.mytext); if (matcher.group(1).startsWith("http://")){ return matcher.replaceAll("&lt;a href=\"$1\"&gt;$1&lt;/a&gt;"); }else{ return matcher.replaceAll("&lt;a href=\"http://$1\"&gt;$1&lt;/a&gt;"); } } catch (Exception e) { return this.mytext; } } } &lt;h:dataTable value="#{bean.dataList}" var="row"&gt; &lt;h:column&gt; &lt;h:outputText value="#{row.linkifiedMyText}" escape="false" /&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload