header image
Home arrow Computing arrow General arrow Howto Escape the dot ('.') in JSF/JSP EL Expressions?
Howto Escape the dot ('.') in JSF/JSP EL Expressions? PDF Print E-mail
Nov 30, 2006 at 10:02 AM

The new common EL expression language introduced with Java Server Faces eases development of modern web applications. A common usage scenario of EL expressions is, for instance, displaying localized text messages on the web-page by accessing the translated text via key from a properties file, e.g.

<f:loadBundle basename="messages" var="msg"/>

<h:outputText value="#{msg.this_is_a_key_for_my_testmessage"/>

A common problem arises when the key contains the dot ('.') character, as the dot has a very special function in EL. The problem is that most developers tend to organize the masses of keys in the properties files by creating some kind of hierarchy using dots in the keys, e.g.:

frontpage.title=blabla

frontpage.subtitle=abcdefg

Using this key directly will cause an error:

  <h:outputText value="#{msg.frontpage.subtitle}"/>

it is required to escape the dot:

  <h:outputText value="#{msg['frontpage.subtitle']"/>

et viola - this will work!

 

Last Updated ( Nov 30, 2006 at 08:45 PM )
A man is truly ethical only when he
obeys the compulsion to help all life which
he is able to assist, and shrinks from
injuring anything that lives.

Albert Schweizer