Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Let's say you have a message key with EL and/or position parameters.

javax.faces.validator.NOT_IN_RANGE=Sorry #{user.name}, the value must be between {0} and {1}

The goal is to resolve this message key in Java, respecting the user's locale, and also have the value be interpolated, meaning the EL and positional placeholders are substituted with actual values.

This involves two steps:

  1. Get a message template from a resource bundle
  2. Perform positional replacement of parameters in message template

The key javax.faces.validator.NOT_IN_RANGE, as shown above, can be resolved within a Seam component as follows:

String template = ResourceBundle.instance()
    .getString("javax.faces.validator.NOT_IN_RANGE");
String resolved = MessageFormat.format(template, 1, 1000);

Note that the replacement is handled using a class from the Java API, the same as what JSF uses internally when a FacesMessage is created.

Seam also supports parameter replacements in a message template, provided by the Interpolator component:

String template = ResourceBundle.instance()
    .getString("javax.faces.validator.NOT_IN_RANGE");
String resolved = Interpolator.instance().
    interpolate(template, 1, 1000);

Which you use is up to you. The Interpolator has its advantages, but is limited to 10 positional parameters. However, when you use Interpolator, it also replaces EL value expressions.