2

I'm creating a JSF Applikation and i would like to get some kind of warning (preferably i the console) if i make typos in my EL-Expression.

Example: On my page i wanted to show some Text that is localized. The locale-config in faces-config.xml is properly set up and works with the var 'msgs'.

I used this code on my page:

<h:outputText value="#{msg.title_edit_customer}"/>

When i checked my Page in the browser, nothing got showed. I took me a while to realize that i made a typo - with #{msgs.... it worked as expected.

Can i activate some kind of Debug-Output, so i can see directly that there is an invalid EL somewhere?

My Setup: Eclipse 4.4.2, Tomcat 8, MyFaces 2.2.8

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
hinneLinks
  • 3,673
  • 26
  • 40

1 Answers1

0

Thanks to @SJuan76 i could figure it out:

  1. Create your own javax.el.ELResolver, all the Methods can return null/false.
  2. Open the Source of the Class org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver and copy the methods facesContext(ELContext) and findScopedMap(FacesContext, Object) (since ScopedAttributeResolver is final, we can't extend it).
  3. Edit the getValue-Method:

    @Override
    public Object getValue(ELContext context, Object base, Object property) {
        if(!context.isPropertyResolved()){
          //Douple Check false-positives
          boolean foundInScope = false;
          final Map<String, Object> scopedMap = findScopedMap(
                facesContext(context), property);
          if (scopedMap != null) {
            Object object = scopedMap.get(property);
            if (object != null) {
                foundInScope = true;
            }
          }
          if (!foundInScope) {
            log.warn(String.format("EL-Property %s couldn't be resolved",
                    property));
        }
    }
        return null;
    }
    
  4. Edit faces-config.xml to register your resolver:

    <application> <el-resolver>com.myPackage.DebugELResolver</el-resolver> </application>

  5. Since there are many Resolvers and each one does a little bit of the Resolving, our new Resolver should come last. Add following to web.xml:

    <context-param> <param-name>org.apache.myfaces.EL_RESOLVER_COMPARATOR</param-name> <param-value>org.apache.myfaces.el.unified.CustomLastELResolverComparator</param-value> </context-param>

  6. Now you'll get some log-Output, every time an expression couldn't be resolved:

03.07.2015 07:34:21 com.myPackage.DebugELResolver [http-nio-8080-exec-2] WARN EL-Property msgx couldn't be resolved

I couldn't figure out how to get the actual EL-Expression (e.g. #{msgx.title_edit_customer}.

hinneLinks
  • 3,673
  • 26
  • 40