+ Start a Discussion

HTML Render of Line Breaks from Address



I've run into a very annoying problem. I have a simple visualforce page that displayes an organizations address pulling from the organization fields, like so:



<apex:outputText value="{!SUBSTITUTE($Organization.Street, '\n', '<br />')}" escape="false" /><br /> <apex:outputText value="{!$Organization.City}" />, <apex:outputText value="{!$Organization.State}" />&nbsp;<apex:outputText value="{!$Organization.Country}" />&nbsp;&nbsp;&nbsp;<apex:outputText value="{!$Organization.PostalCode}" /> <br />

As you can see I'm tyring to replace the new line character with html break tags. Unfortunately it doesn't seem to be picking up the newline character. I really don't want to write custom controller just to generate a string with proper line breaks (this is all the controller would do for this page, I have no need for anything else). Is there a different character for line breaks that I'm missing? 




Paul OveryPaul Overy

I can't figure any way to substitue the \n.  The Substitution clearly works for other characters.  I've tried \r and hex equivalets, but I can't get anything else to work.


You may have already done this part, but if you havent, here is a Custom controller that you try out:


public class myOrgController { Organization org; public myOrgController() { org = [select street, city, state, country, postalcode from Organization]; } public Organization getOrg() { org.street = org.street.replace('\n', '<br/>'); return org; } }






Yeah, I've done that before on other visualforce pages. It just really seemed like a waste for this particular one since that's the only thing it's going to do. Oh well if that's the only way then that's what I'll do :) 



Great idea.  Any thoughts on how to do this for a Visualforce email template?  You can't reference a controller there.



You can do like this directly in your VF page: 

<span style="white-space:pre;">{!$Organization.Street} </span>


For more information about "pre" tag :




Greg RohmanGreg Rohman



I've had the same problem for a while now. The "pre" fix does sorta work, but the pre tag will prevent text from wrapping properly. And I agree that there should be a simple way to do this without needing a custom controller.


What seems to be working for me is to use <apex:outputField> as opposed to <apex:outputText>.  I just tried that, and it correctly keeps any line breaks entered into long text fields. Oddly, the existence of a single <apex:outputField> on my page switches the entire page's font to Arial/sans instead of Times... when I remove the tag, it reverts back to Times. I've not done enough testing yet to determine why the font switches though... perhaps a SF dev can provide some insight.


Hope that helps.




Ran across this in a search and since I've run into this problem before and finally been given the solution, here's what you should use:


<apex:outputPanel rendered="{!cx.Result__c != 'Cancelled'}">{!cx.Result__c}</apex:outputPanel>


Basically, just wrap anything you want to show/hide in an apex:outputPanel and made the Rendered your condition.