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?
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"/>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With