views:

673

answers:

2

In messages.properties:

error.code=This is error message.\nThis is next line of error message.

Now, when I set "errors.rejectValue" with this "error.code" for a form field, I cannot get the line break of '\n' to display on the jsp page when displaying the error message using the form:errors element.

Instead of '\n', using <br/> also does not work and gets displayed as is on the page.

+1  A: 

The layout of distinct lines in an HTML page is not really something that a message bundle can deal with, it's just not suitable for the task. If you need multiple lines to be displayed, then realistically you're going to need multiple messages, with multiple entries in the properties file.

Perhaps you could cook up something which iterates over a sequence of properties, with something like this in your properties file:

error.code.1=This is error message.
error.code.2=This is next line of error message.

It then becomes the job of the JSP to render the sequence of messages. Not very elegant, though, but I can't think of a better solution right now :)

skaffman
+1  A: 

Extending the spring tag form:errors and adding conversion from \n to <br /> is also a non-beatiful solution, but one that will probably work.

Bozho