Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Replacing line breaks with HTML breaks in Velocity

Roller currently has an issue where line breaks in comments are not auto-converted to <br>'s. This problem only exists in the in-page comments and the twisty comments you see on this site. Today, I might've figured out the solution. It turns out that using Jakarta Common's StrutsUtils to replace new lines with <br>'s doesn't work:

#set($comments = $stringUtils.replace($comments, "\n", "<br />"))

However, using the String.replaceAll(new, old) in JDK 1.4 does work:

#set($comments = $comments.replaceAll("\n", "<br />"))

I figured this out on my current project and haven't tested it on Roller. Since I didn't find anything on this via Google - I though y'all might be interested.

Posted in Java at Mar 10 2004, 03:58:26 PM MST 6 Comments
Comments:

I wonder why stringutils.replace() isn't working, since it works in the JSP version?! Weird.

Posted by Lance on March 11, 2004 at 02:23 AM MST #

How about using #set($comments = $stringUtils.replace($comments, "\n", "<br />"))

Posted by Ramesh on March 11, 2004 at 03:56 AM MST #

Use < as ''&lt ; and > as &gt ;

Posted by Unknown on March 11, 2004 at 03:57 AM MST #

Use escape characters for < and >

Posted by Unknown on March 11, 2004 at 03:58 AM MST #

Aaaaaaaah! The in-page comments work again! Yaaah!

Posted by Will Gayther on March 11, 2004 at 05:56 AM MST #

Commons StringUtils works (I hope I've escaped the text properly).

public void testCommonsStringUtils() throws Exception {
VelocityEngine engine = new VelocityEngine();
engine.init();
VelocityContext ctx = new VelocityContext();
ctx.put("stringUtils", new StringUtils());
ctx.put("comments", "this is a \n newline test");
ctx.put("newline", "\n");
ctx.put("break", "<br />");
String template = "#set($comments = $stringUtils.replace($comments,$newline,$break))";
template += "$comments";
StringWriter writer = new StringWriter();
engine.evaluate(ctx, writer, "", template);
assertEquals("this is a <br /> newline test", writer.toString());
}

Posted by Anonymous on March 12, 2004 at 05:09 PM MST #

Post a Comment:
  • HTML Syntax: Allowed