fn:replace carriage return with br

So I have a String that needs to be passed through as a javascript method argument. Problem is this String is user input and therefore can contain newlines so code can be scattered over multiple lines resulting in js syntax errors, example:

functionName("a correct string argument","this one is
scattered over multiple lines and therefore generates js syntax errors");

Easy, lets replace these newlines with the fn:replace tag… Didn’t turn out to be so simple at all, “\\\r\\\n” is not accepted with jstl. Read the following threads for some suggestions:



Important! In case of just formatting (not syntax problem like me) you can always use

 + css 

Eventually I just created an extra getter in my model returning the corrected string, if you don't know how to do this see:


When always running on the same system you can also use System.getProperty("line.separator") in your replace.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait