Avoiding javax.el.PropertyNotFoundException for resource bundle lookups in jsf 2.1 + spring 3

StackOverflow https://stackoverflow.com/questions/9912120

سؤال

We have defined properties in several resource bundles, which are configured in the faces-config.xml

<resource-bundle>
<base-name>webMessages</base-name>
<var>feBundle</var>
</resource-bundle>

We then try to access a property which is not defined.

<tag infoText="#{feBundle['insurance.comparison.household.details.aicraftCrash.tooltip']}"

/>

If the property is not available a javax.el.PropertyNotFoundException is thrown and causes the faces servlet to render a blank page. From the documentation of the ResourceBundleELResolver this should not happen, as it does not throw this exception. I can see it is part of the resolvers of the DemuxCompositeELResolver.But it seems it is never called. Instead the MapELResolver (which is placed after the RBELResolver in the list of resolvers) is called and throws an exception. I can't really make something of that behaviour and debugging is tedious. There must be some way to get around this. A missing property can not break my whole page rendering process. Any ideas?

Note: This is an issue only with the javax.el library as provided with tomcat > 6 distributions

هل كانت مفيدة؟

المحلول

I investigated the issue a bit further and found that it is caused by the implementation of javax.el package in the tomcat distribution. So the described behaviuor only occurs when using tomcat > 6. I filed a bug report in their bug tracking tool already although one can argue that it is not a real bug but a sort of wanted (but, IMHO, ugly) behaviour. I also found a solution for jsf.

Subclass the ResourceBundleELResolver and override its getValue(...) method. Change it such that it sets the PropertyResolved attribute to true before any exception might occur.

 if (base instanceof ResourceBundle) {
        if (property != null) {
            try {
                context.setPropertyResolved(true);
                Object result = ((ResourceBundle) base).getObject(property
                        .toString());
                return result;
            } catch (MissingResourceException mre) {
                System.out.println("Missing property: " + property);
                return "?" + property.toString() + "?";
            }
        }
    }

Register this custom resolver in the faces-config.xml with

<el-resolver>your.package.TheResolverImplementation</el-resolver>

And the link to the bug report https://issues.apache.org/bugzilla/show_bug.cgi?id=53001

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top