File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to put carriage return in MessageResource.properties? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to put carriage return in MessageResource.properties?" Watch "How to put carriage return in MessageResource.properties?" New topic
Author

How to put carriage return in MessageResource.properties?

Jonilie Echavez
Greenhorn

Joined: Jun 26, 2009
Posts: 20
My Struts MessageResource.properties file has the following key, where i wanted to insert a carriage return after the message.

error.duplicate=Duplicate record found.\n

But in the output of the jsp file, the message is displayed with the '\n' instead of the carriage return expected.

Output:
Duplicate record found.\n

How do i properly insert this escape character?

Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
Did you try:

error.duplicate=Duplicate record found.<br>
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
hi Jonilie Echavez

i think you want to display the error message in the list format. if your aim is so then use the following.

errors.header=<UL><font color="red" face="Arial" size="1">
errors.prefix=<LI>
errors.suffix=</LI>
errors.footer=</font></UL>

put the above in the top of the properties file.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Personally, I think it's a bad idea to keep formatting information like this in a resource file.
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
hi david
then how to show the errors in the list format. i cant use the <li> tag every where i have to show the error message in the jsp file. please tell me the alternate idea you have.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

I'm not sure what you are doing when you output this error message, so this may not be relevent but I reckon that you could avoid this issue with the use of CSS and properly formatting your HTML. If for example you're trying to get the errors to appear next to an input then take a look at this tutorial: http://articles.sitepoint.com/article/fancy-form-design-css/7

If you are wanting it to appear in a list form (I'm assuming here that you take in a list of error messages) do it in the JSP and certainly not from your messages file:


I have to say though the most simple way is just to style it using some html/css.

Sean

I love this place!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Prakash Attur wrote:hi david
then how to show the errors in the list format. i cant use the <li> tag every where i have to show the error message in the jsp file. please tell me the alternate idea you have.

Why not? Or why not create a custom tag to do it?

My point is that embedding things like <br> tags in the resource file is a pain, and explicitly ties the error message to the page layout. The idea behind things like resource files is to separate concerns.
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
oh yes very good idea...thanks David..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to put carriage return in MessageResource.properties?
 
Similar Threads
Can I validate my form using Struts-Portlet framework functionality
Carriage return in a JOptionPane
Adding a carriage return to a Node
JTextPane and new lines
problem with inserting formatted text