0

For testing / debugging purpose, I want to show the keys from the message bundle instead of the values in my jsf application. Is that possible?

Example: My messages_en.properties has following entry:

global_today=today   

example jsf page

<h:outputLabel id="myId" value="{Msgs['global_today']}"/>   

Now I want to see the key in the page, "global_today" not today.

h2mch
  • 521
  • 5
  • 23

1 Answers1

0

Simplest way is to rename the properties file, that way JSF wont find any key and you instead of 'today' you will see ???global_today???

If you still want to see the global_today you can do the following:

Lets say you have the following in your faces-config.xml

<resource-bundle>
    <base-name>my.package.resources.MyText</base-name>
</resource-bundle>

Rename the MyText into MyTextExtender

Then in add MyTextExtender.java in the my.package.resources package

with the following content:

public class MyTextExtender extends ResourceBundle {

    public MyTextExtender() {
        setParent(getBundle("my.package.resources.MyText", FacesContext.getCurrentInstance()
                .getViewRoot().getLocale()));
    }

    @Override
    public Enumeration<String> getKeys() {
        return parent.getKeys();
    }

    @Override
    protected Object handleGetObject(String key) {
        return key;
        //The code below will try to turn the annoying ???some_key??? 
        //into "some key" (looks better)
        /*try {
            return parent.getObject(key);
        } catch (MissingResourceException e) {
            if (!StringUtils.isEmpty(key)) {
                logger.error("Missing key: " + key + " in the properties", e);
                return key.replace("_", " ");
            } else {
                logger.error("Key was null???", e);
                return "";
            }
        }*/
    }
}
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • This page (http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/ ) pointed me already in this direction and that works. – h2mch May 20 '14 at 09:44
  • Well, eventually most JSF related solution comes from **BalusC** :) – Daniel May 20 '14 at 10:19