JSF Object Not Found

I recently decided to try writing my own JSF component as I had a need that wasn’t met by the excellent PrimeFaces component library. I had read some horror stories about how hard it is to write custom components so I’d put off doing it as I didn’t want to get bogged down when I had so much else to be getting on with. In reality it turned out to be quite simple but that’s another story.

What I would like to address here is a mistake that cost me about two hours and it just too stupid for words. I’d correctly created my new component and registered it in the taglib.xml and the faces-config.xml files then packaged it up in a jar. However, when I ran up my demo application I received this error message from the page containing the component:

javax.faces.FacesException: Expression Error: Named Object: foo not found.

I think I read every single page Google found on this error message and not one of them helped. The most likely cause was the component-type value being different in the two configuration files but this wasn’t the case – I triple checked. I guessed that the problem was a failure to find the class but I was sure that it was on the classpath. JSF gets the class for a particular object name by looking in the faces-config.xml file so I checked that again – the type and classname were correct. In frustration I copied the the component declaration from the faces-config.xml in my component library into the faces-config.xml file of my demo application.

Upon firing up the demo application the component worked perfectly. I was now pretty sure that the problem was with the faces-config.xml file in my component library but I couldn’t see anything wrong with it. Then it struck me – drum roll for the worlds most ridiculous bug – when I created the faces-config.xml file NetBeans helpfully added the .xml extension for me. The trouble was I also typed the .xml extension so my file ended up being called faces-config.xml.xml. As soon as I pulled off the additional extension everything started working as it should.

Hopefully this will be of some help to the dozens of other people that have suffered with this error message but found no solution online.

Posted in Java EE and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.