I have a bean that is filled in by a database in the Action
and then displayed via JSP. One of the attributes of this
bean is a code that can be 001, 002, 003, or 004. In
the output, this code needs to be mapped to a word and this
word needs to be localized.

Sounds like an easy problem but I can't find an easy way to
do this. Right now I have the strings I need mapped in the
properties file as:

        term.type001=string1
        term.type002=string2
        term.type003=string3
        term.type004=string4

What I'd like to do is something like:

        <bean:message key="term.type<%=bean.getType()%>"/>

Of course, this doesn't work. So what I am actually doing is
adding a new method to the bean which duplicates the code
in <bean:message> so that the bean can do the mapping for me.
I then display the string with:

        <%= line.getTypeMessage(pageContext) %>

This is ugly for a few reasons:

        1) It is a scriptlet.
        2) It makes the bean do work that a "view" should do.
        2) It passes the pageContext to a bean (for Locale).
        3) It duplicates code from <bean:message>.

Can anyone think of a better way?

Devon

Reply via email to