function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrianWKBrianWK 

Line breaks within String for inputTextarea and outputtext

I have a non-sobject field called "InvoiceDates" in my controller extension. On the VF page there is both an InputTextarea and an outputtext for the same field. The idea is the inputtextarea is pre-populated, but editable by the user. When the user updates that field and clicks a refresh button, they can see a "preview" of the document that will be created.

 

So far things work great for the inputtext area. I placed \n in the string which provides my line breaks. However when I go to output the value it shows up on a single line.

 

Part of method defining string

string vDate = string.valueof(StartDate.Month() +'/'+ StartDate.Day()+'/'+ StartDate.Year()); String Term = 'Term ' + string.valueof(i+2) + ': '; InvoiceDates = InvoiceDates + Term + Vdate + '\n';

VF Page area

 

(this works)

<apex:inputtextarea value="{!InvoiceDates}" id="InvoiceDates" style="width:300px;height:150px"/>

(Output not displaying with line breaks) <apex:outputtext value="{!InvoiceDates}" /> (Also tried) {!InvoiceDates}

 

the component references says outputtext "escape the rendered text if it contains sensitive HTML and XML characters" I'm assuming that using outputtext would "strip" my \n, so I tried just placing the string without an outputtext - but get the same data string line.

 

The only way I have been able to work around this is to create a list<string> instead of a concatenated String. This works on the display, but doesn't work for the user Inputtextarea well. Any suggestions on how I can get my output to include the \n ?

DuFreyDuFrey

What about escaping the apex:outputText and using <br /> like this:

 

<apex:outputtext escape="false" value="{!InvoiceDates}" />
 InvoiceDates = InvoiceDates + Term + Vdate + '<br/>';
BrianWKBrianWK

DuFrey,

 

that works great for the outputtext, but it then add <br/> in the inputfield. Since this is going to be released to non-html or that tech savvy people, we dont' want to have them put <br/> into their code.

 

One way I found that is a work around is setting the INvoiceDates to an Sobject TextArea field - but I really don't want to create a new field just for InvoiceDates which doesn't need to be maintain beyond the document creation.

jwetzlerjwetzler

I'm not 100% sure I'm following you, but if you need a throwaway text area field you can use an object proxy.

 

Something like:

 

 

Account delegate = new Account(); public Account getDelegate() { return delegate; }

 

public PageReference save() {

InvoiceDates = delegate.description;

 

<apex:inputField value="{!delegate.description}"/> 

 

 You get the idea.  Just use the account as a temporary placeholder to give you access to the text area metadata, but save the actual value elsewhere.

 

The caveat here is that all of your users need to have read/write access to account and account.description, since inputField obeys both CRUD and FLS rules.

 

trsmithtrsmith
Instead of 
 

<apex:outputtext value="{!InvoiceDates}" />

 

 for your output, you'll want to use
 

<apex:outputField value="{!InvoiceDates}" />

 

That'll preserve the format of the text area on output.

Message Edited by trsmith on 06-04-2009 02:13 PM