views:

188

answers:

1

I need to have resource messages that contain EL expressions be resolved when loaded from a ResourceBundle. Basically I have a number of properties files containing the text. Some of the text will look like the following:

welcomeText=Welcome #{userbean.name}

The only possible way I can see this working currently is implementing a custom taglib so that instead of saying:

<f:loadBundle var="messages" basename="application.messages"/>

I would have to use

<mytaglib:loadBundle var="messages" basename="application.messages"/>
#{messages.welcomeText}

Given a user with username "User1", this should output

Welcome User1

My implementation would then use a custom ResourceBundle class that would override handleGetObject, use the ELResolver to resolve variables etc....Ideas? suggestings? Implementations that are already available?

I appreciate your assistance.

A: 

Rather make use of <h:outputFormat> and <f:param> to display parameterized text. It's backed by the MessageFormat API, the same rules as described in the API's javadoc will be applied.

E.g.

welcomeText=Welcome {0}

with

<h:outputFormat value="#{messages.welcomeText}">
    <f:param value="#{userbean.name}" />
</h:outputFormat>

There it is for :)

BalusC
I know about MessageFormat, but I am specifically looking for a way of resolving variables from inside property files. It is possible that different locales will have different messages with different variables being used for the textual output.
CDSO1
Well, that pretty much tight-couples the bundle with the model. The bundle maintainer has to know precisely about the models used. By the way, you can also just use `{1}`, `{2}`, `{n}` and so on and just feed them all and clearly document which one stands for what value. The ones not specified in the bundle will be plain ignored.
BalusC