How to insert <br /> tags into a java String
facelets, java, jsf, regex, xhtml
Solution
You need to disable the (default) HTML escaping of text. You can do that with `h:outputText` (or any RichFaces equivalent for that) with the `escape` attribute set to `false`.
<h:outputText value="#{bean.property}" escape="false" />
Problem
I am trying to insert line break tags into some text and displaying it on a web page. The < and > signs are being translated into `<` and `>` and the tags are showing up as text on the web page. The text looks like this when I select it from the database (I've output it to SYSOUT): ``` version 12.4 service timestamps debug datetime service timestamps log datetime service password-encryption ``` Then I run it through this little filter: ``` public DevConfigs getDevConfig() { String config = devConfig.getConfig(); Pattern pattern = Pattern.compile(".$", Pattern.MULTILINE | Pattern.DOTALL); Matcher matcher = pattern.matcher(config); String newConfig = matcher.replaceAll("<br />"); devConfig.setConfig(newConfig); return this.devConfig; } ``` Here is the web page (it's a Seam application using facelets): ``` <rich:tab label="Config"> hello<br /> there<br /> #{devConfig.config} </rich:tab> ``` And the page source looks like this: ``` hello<br /> there<br /> <br /> <br /> version 12.<br /> service timestamps debug datetim<br /> service timestamps log datetim<br /> service password-encryptio<br /> <br /> ``` As you can see, my tag comes out as HTML characters and not as tags. What do I need to do to insert line break tags at the end of each line of text?? TDR