3

i have one long text area field and i used it on my visualforce. my long text area field value is

- Fees are valid only for the payment of the Grade specified in this Letter of Offer.\n- Fees include: 2 sets of school uniforms, fieldtrip around the xxx area, E-Book material, and in-house co-curricular activities.\n- Request for changes to instalment plans must be made 10 days prior to the due date of the payment.\n- Terms and Conditions from the Admissions Policy will apply.

, the idea is i change all '\n' to <br/> so it can put line break in one field. here's my visualforce look like

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\n','<br/>')}" style="white-space:pre;" escape="false"/>

the outcome is not like my expected

  • Fees are valid only for the payment of the Grade specified in this Letter of Offer.\
  • Fees include: 2 sets of school uniforms, fieldtrip around the JABODETABEK area, E-Book material, and in-house co-curricular activities.\
  • Request for changes to instalment plans must be made 10 days prior to the due date of the payment.\
  • Terms and Conditions from the Admissions Policy will apply.

in every end of the list there is '\' symbol. i don't know where it comes. Do you have any idea about this ?

6

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\n','<br/>')}" style="white-space:pre;" escape="false"/>

change this into this

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\\\n','<br/>')}" style="white-space:pre;" escape="false"/>

It will works for you. Thanks for the update @VigneshwaranG

  • it didn't work bro. i already use it but no use. have any idea? – Febrian Tarigan Oct 2 '15 at 16:01
  • 1
    Use \\\n since you need to escape the escape character added for escaping \ – Vigneshwaran G Oct 2 '15 at 16:43
2

a more simple and best solution would be to add the css pre-wrap which conserves New lines, Spaces and tabs, Text wrapping

  <apex:outputtext style="white-space:pre-wrap;" value="{!donationText}" escape="false" /><br /> 

Please note donationText is a long text area

1

Like @VigneshwaranG said. just create escape character for escaping .

so i replace \n to \\\n

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.