+ Start a Discussion
SandrineSandrine 

adding space in controller that can be preserved in VF page outputText


I am populating a field like below
repairCenterAddress = '';
        if(String.isNotBlank(caseObj.Repair_Center_Street__c))
            repairCenterAddress = repairCenterAddress+caseObj.Repair_Center_Street__c;
        if(String.isNotBlank(caseObj.Repair_Center_ZIP_Code__c))
            repairCenterAddress = ' '+repairCenterAddress+caseObj.Repair_Center_ZIP_Code__c;
        if(String.isNotBlank(caseObj.Repair_Center_City__c))
            repairCenterAddress = ' '+repairCenterAddress+caseObj.Repair_Center_City__c; 
        if(String.isNotBlank(caseObj.Repair_Center_State__c))
            repairCenterAddress = ' '+repairCenterAddress+caseObj.Repair_Center_State__c;
        if(String.isNotBlank(caseObj.Repair_Center_Country__c))
            repairCenterAddress = ' '+repairCenterAddress+caseObj.Repair_Center_Country__c;


I am displayuing like below
<apex:outputText  value="{!repairCenterAddress}}"/>
the space i added ' ', between two ' , doesnt get counted, the whole text is displayed without spaces between two fields.

Is there way i can added spaces in controller that can be preserved in VF page.

Thanks for suggestion !
 
Best Answer chosen by Sandrine
edelrabeedelrabe

It's strange that a space is not shown. Maybe it's a styling issue.
Try to use non-breaking space html symbol &nbsp;
In order to display it properly you need to use escape="false" withing apex:outputText

repairCenterAddress = '&nbsp;' + repairCenterAddress+caseObj.Repair_Center_Country__c;
<apex:outputText value="{!repairCenterAddress}" escape="false" />