I have an <f:viewParam>
tag on JSF pages that sets GET parameters to the corresponding managed bean after conversion and validation.
If either conversion or validation errors occur, then an appropriate error message is fetched from a resource bundle and displayed on <p:messages>
(may also be <p:growl>
or <h:messages>
).
The application is multilingual. Therefore when a different language is selected, a message should be displayed in that language but it always displays the message according to the default locale en
(for English).
Test.xhtml:
<!DOCTYPE html>
<html lang="#{localeBean.language}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="#{localeBean.locale}">
<f:metadata>
<f:viewParam name="id" converter="#{myConverter}" />
</f:metadata>
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:messages />
</h:body>
</f:view>
</html>
The converter:
@FacesConverter("myConverter")
public final class MyConverter implements Converter
{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
ResourceBundle bundle = context.getApplication()
.evaluateExpressionGet(context, "#{messages}", ResourceBundle.class);
String message = bundle.getString("id.conversion.error");
throw new ConverterException(
new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
throw new UnsupportedOperationException(); // Not relevant in this problem.
}
}
Except for the messages from <f:viewParam>
, there is no problem. All other kind of messages are displayed in the language selected by the user.
Is there anything special with <f:viewParam>
?
evaluateExpressionGet(String expression)
. I can see onlypublic <T> T evaluateExpressionGet(FacesContext context, String expression, Class<? extends T> expectedType) throws ELException
instead. Is it there? – Chibouk