You need to sign in to do that
Don't have an account?

CR/LF in apex:outputField()
I am using apex:outputField(..) with a standard object and display textwith linebreaks. That output reflects the linebreaks nicely.
After that I need to compile a list of data from activities which Ido in a custom object (see code below). That data can only be displayedwith apex:outputText. I made sure that \r\n is in the string (seecode), but it does not break the lines.
In the code you will find that I arteficially entered theseescaped characters and a line before and after ("|\r\n|"). In thedisplay, ist shows some space between those 2 lines. That indicatesthat the \r\n are not suppressed, but not used in apex:outputText. Ialso tried to arteficially use </br>, but that is printed ratherthan uased as HTML break.
How do I get linebreaks in apex:outputText ??
Thanks for your help.
-------------- 8< cut! -------------------------------------------------------------------------------
VF page:
<apex:page tabstyle="Case" controller="Report1"
standardStylesheets="false" showHeader="false">
<apex:stylesheet value="{!URLFOR($Resource.printstyles, 'printstyles.css')}" />
<apex:pageBlock title="Zwischenbericht ({!Case.CaseNumber})" mode="detail" id="pageblock">
<apex:pageMessages />
<div id="massfields">
<div id="masssection">
<div id="masslabel"><apex:outputLabel for="descr" value="Bemerkung" /></div>
<div id="massline"><apex:outputField value="{!case.Description}" id="desc" /> </div>
<!-- ^^^ This output shows new lines as wanted -->
</div>
</div>
<apex:pageblockSection title="Aktivitäten">
<apex:repeat value="{!kontaktInfo}" var="kontakt" id="task">
<div id="activitydescription"><apex:outputTextvalue="{!kontakt.Description}" /> </div>
<!-- ^^^ This output DOS NOT show new lines as wanted -->
</apex:repeat>
</apex:pageblockSection>
</apex:pageBlock>
</apex:page>
--------------------------------------------------------------------------------
Controller:
public with sharing class Report1 {
private Case locCase;
private List<Involvierte_Partei__c> invParty;
private BOKontaktInfoLister kontaktlist;
public Report1(){
String id = ApexPages.currentPage().getParameters().get('id');
buildDataStructure(id);
}
public Report1(String id){
buildDataStructure(id);
}
private void buildDataStructure(String id){
locCase = [..];
kontaktList = new BOKontaktInfoLister(id);
}
public Case getCase(){
return locCase;
}
public List<DOKontakt> getKontaktInfo(){
return kontaktList.getKontaktInfo();
}
}
--------------------------------------------------------------------------------
public class BOKontaktInfoLister{
private List<Task> tasks;
private List<Event> events;
private List<DOKontaktInfo> kontaktList; //DOKontaktInfo is just a DataObject
public BOKontaktInfoLister(String id){
kontaktList = new List<DOKontaktInfo>();
tasks = [Select t.ActivityDate, t.Account.PersonMobilePhone,t.Account.PersonHomePhone, t.Subject, t.Id, t.Description From Task twhere t.What.Id = :Id order by t.ActivityDate asc];
events = [select e.ActivityDate, e.Account.PersonHomePhone,e.Account.PersonMobilePhone, e.Subject, e.Id, e.Description From Evente where e.What.Id = :Id order by e.ActivityDate];
for(Integer i = 0; i< tasks.size(); i++){
DOKontakt kon = new DOKontakt();
kon.id = tasks[i].Id;
...
//kon.description = tasks[i].Description; // real statement
kon.description = 'Line1\r\n</br>Line2'; // this is just mytest to be sure that I have line breaks in the text
kontaktList.add(kon);
}
for(Integer i = 0; i< events.size(); i++){
DOKontakt kon = new DOKontakt();
kon.id = events[i].Id;
...
//kon.description = events[i].Description; // real statement
kon.description = 'Line1|\r\n|Line2'; // this is just my test to be sure that I have line breaks in the text
kontaktList.add(kon);
}
}
public List<DOKontakt> getKontaktInfo(){
return kontaktList;
}
}
--------------------------------------------------------------------------------
public class DOKontakt{
public String id;
public Date activityDate;
public String subject;
public String name;
public String privPhone;
public String mobPhone;
public String description;
public String getId(){
return id;
}
public Date getActivityDate(){
return activityDate;
}
public String getSubject(){
return subject;
}
public String getName(){
return name;
}
public String getPrivPhone(){
return privPhone;
}
public String getMobPhone(){
return mobPhone;
}
public String getDescription(){
return description;
}
}
After that I need to compile a list of data from activities which Ido in a custom object (see code below). That data can only be displayedwith apex:outputText. I made sure that \r\n is in the string (seecode), but it does not break the lines.
In the code you will find that I arteficially entered theseescaped characters and a line before and after ("|\r\n|"). In thedisplay, ist shows some space between those 2 lines. That indicatesthat the \r\n are not suppressed, but not used in apex:outputText. Ialso tried to arteficially use </br>, but that is printed ratherthan uased as HTML break.
How do I get linebreaks in apex:outputText ??
Thanks for your help.
-------------- 8< cut! -------------------------------------------------------------------------------
VF page:
<apex:page tabstyle="Case" controller="Report1"
standardStylesheets="false" showHeader="false">
<apex:stylesheet value="{!URLFOR($Resource.printstyles, 'printstyles.css')}" />
<apex:pageBlock title="Zwischenbericht ({!Case.CaseNumber})" mode="detail" id="pageblock">
<apex:pageMessages />
<div id="massfields">
<div id="masssection">
<div id="masslabel"><apex:outputLabel for="descr" value="Bemerkung" /></div>
<div id="massline"><apex:outputField value="{!case.Description}" id="desc" /> </div>
<!-- ^^^ This output shows new lines as wanted -->
</div>
</div>
<apex:pageblockSection title="Aktivitäten">
<apex:repeat value="{!kontaktInfo}" var="kontakt" id="task">
<div id="activitydescription"><apex:outputTextvalue="{!kontakt.Description}" /> </div>
<!-- ^^^ This output DOS NOT show new lines as wanted -->
</apex:repeat>
</apex:pageblockSection>
</apex:pageBlock>
</apex:page>
--------------------------------------------------------------------------------
Controller:
public with sharing class Report1 {
private Case locCase;
private List<Involvierte_Partei__c> invParty;
private BOKontaktInfoLister kontaktlist;
public Report1(){
String id = ApexPages.currentPage().getParameters().get('id');
buildDataStructure(id);
}
public Report1(String id){
buildDataStructure(id);
}
private void buildDataStructure(String id){
locCase = [..];
kontaktList = new BOKontaktInfoLister(id);
}
public Case getCase(){
return locCase;
}
public List<DOKontakt> getKontaktInfo(){
return kontaktList.getKontaktInfo();
}
}
--------------------------------------------------------------------------------
public class BOKontaktInfoLister{
private List<Task> tasks;
private List<Event> events;
private List<DOKontaktInfo> kontaktList; //DOKontaktInfo is just a DataObject
public BOKontaktInfoLister(String id){
kontaktList = new List<DOKontaktInfo>();
tasks = [Select t.ActivityDate, t.Account.PersonMobilePhone,t.Account.PersonHomePhone, t.Subject, t.Id, t.Description From Task twhere t.What.Id = :Id order by t.ActivityDate asc];
events = [select e.ActivityDate, e.Account.PersonHomePhone,e.Account.PersonMobilePhone, e.Subject, e.Id, e.Description From Evente where e.What.Id = :Id order by e.ActivityDate];
for(Integer i = 0; i< tasks.size(); i++){
DOKontakt kon = new DOKontakt();
kon.id = tasks[i].Id;
...
//kon.description = tasks[i].Description; // real statement
kon.description = 'Line1\r\n</br>Line2'; // this is just mytest to be sure that I have line breaks in the text
kontaktList.add(kon);
}
for(Integer i = 0; i< events.size(); i++){
DOKontakt kon = new DOKontakt();
kon.id = events[i].Id;
...
//kon.description = events[i].Description; // real statement
kon.description = 'Line1|\r\n|Line2'; // this is just my test to be sure that I have line breaks in the text
kontaktList.add(kon);
}
}
public List<DOKontakt> getKontaktInfo(){
return kontaktList;
}
}
--------------------------------------------------------------------------------
public class DOKontakt{
public String id;
public Date activityDate;
public String subject;
public String name;
public String privPhone;
public String mobPhone;
public String description;
public String getId(){
return id;
}
public Date getActivityDate(){
return activityDate;
}
public String getSubject(){
return subject;
}
public String getName(){
return name;
}
public String getPrivPhone(){
return privPhone;
}
public String getMobPhone(){
return mobPhone;
}
public String getDescription(){
return description;
}
}
You should use <BR/>, as the you need the browser to generate the line break.
When you use outputText there is an attribute called escape - if you set that to true then you should get your line break.
This is not working when i export the data into csv file.
how to make work CR+LF when exporting csv