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:
http://forum.java.sun.com/thread.jspa?threadID=614154&messageID=3427211
Important! In case of just formatting (not syntax problem like me) you can always use
+ cssEventually I just created an extra getter in my model returning the corrected string, if you don't know how to do this see:
http://www.rgagnon.com/javadetails/java-0454.html
When always running on the same system you can also use
System.getProperty("line.separator")
in your replace.note to myself: I need to look into
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html#wp77078