quote

venerdì, gennaio 09, 2009

spring message tag libray

If you are using spring message tag library you know how much is annoying get a runtime exception in the case you have inserted a wrong code as attribute.
For every message code tag library you define in your jsp you have to add the corresponding property entry in the message.properties file but can happen you forget to insert it or maybe you insert a wrong value.
For example having such tl message where the code is Email

<spring:message code="Email" />

I have to define the corresponding entry in the file message.properties, or in more files depending on the type of internationalization I use.

Email=E-Mail

A way to avoid to get the runtime exception, in case of wrong code, is to add the property text to the message tl. In case of not matching the value of text will appear in the page and you could fix the problem after. Better to use text property with ? before and after the string so that you can easily understand there is a wrong value of code.
Therefore use

<spring:message code="Email" text="?Email?"/>

As usual, thanks to Lucio.