Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert new line in struts2 messages.properties

I want to display the error message in two lines in Struts2

User Name is not valid
Password is not valid

and my property is:

username.password.errrorMsg: User Name is not valid \n Password is not valid.

I added \n but its displaying in single line.

Can you suggest to display in two lines?

like image 939
sree Avatar asked Feb 14 '23 01:02

sree


2 Answers

If you use a message format then \n symbol add a new line character. If you want to display this message with actionerror or actionmessage tags you need to use <br> and let it not escape. For example

<s:actionmessage escape="false"/> 
like image 144
Roman C Avatar answered Feb 17 '23 03:02

Roman C


Because new line/breaking character depends on where do you use/show message it is better to use different messages for that.

invalid.userName = User Name is not valid
invalid.password = Password is not valid

In this way you can use them separately in case you want to show specific message and display them as you want.


If you displaying them in HTML/JSP using S2 <s:text> tag then <br/> should work. But several tags are escaping HTML so for example to use this kind of message in <s:property> with getText() you need to set escapeHTML attribute to false.

like image 28
Aleksandr M Avatar answered Feb 17 '23 02:02

Aleksandr M