Pregunta

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?

¿Fue útil?

Solución

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"/> 

Otros consejos

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.

Probably < br/> (without the space between < and b :P), as the output format is html.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top