jsfrichfacesfaceletsgatein

How to see message.properties in a Jar using JSF?


Using: JSF 1.2, Facelets 1.1.15, GateIn 3.1 GA, Richfaces 3.3.3

I have some common .xhtml and backing bean in a JAR that our portlets can see. I did this by overriding ResourceResolver as described in other posts:

The portlets can load the XHTML and use the backing bean.

Here is my problem: I cannot get the xhtml to substitute the messages defined in messages_en.properties. I have tried moving the properties file outside of the JAR and placing directly in /lib folder. I have also tried putting a / in front of the name to try to get the resolver to find it. I have also put it in the components folder.

The common jar info is: I hava a my-portlet-common-resources.jar which resides in server/my-portal/lib. The jar is structured like so:

faces-config.xml contents:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">

    <application>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
        <message-bundle>/messages_en.properties</message-bundle>
    </application>

    <managed-bean>
        <managed-bean-name>FilterCreateBean</managed-bean-name>
        <managed-bean-class>com.portlet.common.FilterCreateBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

</faces-config>

Include the messages in commonPopups.xhtml (partial snip):

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

    <a4j:loadBundle basename="messages" var="msgs"/>

    <rich:panel style="border-style:none;" id="addNewChainPanel">
    <rich:modalPanel id="modalNewChainPanel" autosized="true">
        <f:facet name="header"><h:outputText value="#{msgs['filterset.modal.new.title']}" /></f:facet>

</ui:composition>

Solution

  • This should work. Perhaps you already have a messages*.properties file in the classpath root of your main webapp. This one has then precedence in classloading. You need to put it in a more specific package. Put the JAR's one in for example the com/portlet/common folder so that it becomes member of the com.portlet.common package. This way it'll be available by:

    <a4j:loadBundle basename="com.portlet.common.messages" var="msgs"/>
    

    Unrelated to the concrete problem, the <message-bundle> entry in faces-config.xml has a completely different purpose. It's supposed to override JSF default validation/conversion messages which are returned by JSF default validators/converters. It is not intended to provide localized content. There you use the <resource-bundle> entry or <xxx:loadBundle> tag for. I'd remove that entry from the faces-config.xml.