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

Use of '\n' for line feed in Error strings
Since visualForce doesn't have good error handling for custom controllers, I am writing some custom code show error messages.
My custom controller is editing a table.
In the code below, I am a trying to insert a line feed after every error using '\n'.
However, when error messages are output, there are no separate lines - it is one big error message. i have tried '\r' as well - doesn't work.
Any thoughts.
My custom controller is editing a table.
In the code below, I am a trying to insert a line feed after every error using '\n'.
However, when error messages are output, there are no separate lines - it is one big error message. i have tried '\r' as well - doesn't work.
Any thoughts.
Code:
} catch (DmlException e) {
for (Integer i = 0; i < e.getNumDml(); i++) { string[] fields = e.getDmlFields(i); //strip __c string field = fields[0].subString(0,fields[0].length()-3); integer row = e.getDmlIndex(i); String rowError = 'Row:' + (row+1) + ' Field:' + field + ':' + e.getDMLMessage(i); if (ErrorString[0] <> null) { ErrorString = ErrorString + '\n' + rowError; } else { ErrorString = 'ERROR:' + rowError + '\n'; } }
Slash n is valid in all strings. I use the slash n all the time.
By the way, your code looks suspect in that there is no declaration for ErrorString and you evaluation of ErrorString[0]
Cheers
ErrorString[0] - that issue doesn't exist in my code - I used an array of ErrorString - so my code internally always says ErrroString[0]. I had just cleaned up the code for this posting so as to not confuse the issue.
I have noticed the <> as well. Seems like it does the same thing as !=.
I was hoping it would do it...
I get the string <br> in the output instead of line break. When I put \n, the system strips it out and I get no breaks
Perhaps it has something to do with the visualforce processing.
I am using the errorstring in the following fashion in a VisualForce page:
<apex:outputPanel rendered="{!errorOccured1}">
<apex:outputText value="{!ErrorString1}" />
</apex:outputPanel>
On your OutputText, add an escape="false" attribute, so the <BR> will render as html correctly.
Jon
Message Edited by J Keener on 05-13-2008 12:54 PM
Message Edited by J Keener on 05-13-2008 12:55 PM
For some reason, the following code will not properly escape the contents:
<apex:outputText escape="false">
{!someTextWithBRTags}
</apex:outputText>
But the following code will escape contents:
<apex:outputText escape="false" value="{!someTextWithBRTags}"/>
Hi,
The following worked fine for me.
The String was created in the Controller class with a combination of '\n<br/>'.
(Something like String str="This is line 1"+"\n<br/>"+"This is line2";)
I tried with this escape sequence as using only \n or only <br/> did not help me.
Setting the escape as false in Visualforce page is also needed for this to display correctly.
<apex:outputText value="{!str}" escape="false/>
Regards,
Vineetha