Is faces-config.xml and web.xml needed nowadays?

2.2k views Asked by At

I have been studying JavaEE8 and practicing with some projects, understanding the new technologies like Servlet 4.0 and JSF 2.3. I have read in many forums and pages, in some I see that they say that web.xml and faces-config.xml are not necessary, because annotations are now used, but in some others they continue to use them.

In which cases should you continue to use the Web Deployment Descriptor-> web.xml and the application configuration resource file-> faces-config.xml?

2

There are 2 answers

0
SCPhantom On

They aren't required, but I'd highly recommend to use them since you'll need them sooner or later for additional configuration anyways.

The annotations are used to achieve better readability and to simplify the faces-config.xml and web.xml, however they do not even nearly allow for the configuration options that can be made in the configuration files. For example you can use the @FacesValidator Annotation instead of declaring and referencing the corresponding class in the faces-config.xml.

A task that can't be achieved by using annotations would be the declaratation of a welcome page. If you want to specify it, you need the web.xml.

4
David Ferreira On

I found a specific problem in the Mojarra implementation of JSF 2.3 when using the web.xml or faces-config.xml file. In the code of this implementation, the ELUtils class has the following condition:

if (getFacesConfigXmlVersion(facesContext).equals("2.3") || getWebXmlVersion(facesContext).equals("4.0")) {
                throw new FacesException("Unable to find CDI BeanManager");
}

which throws an exception: "Unable to find CID BeanManager". I only had the faces-config.xml file with the latest version of JSF specified in the namespace and I was throwing that exception.

To avoid this problem, you can specify a different version of JSF (before 2.3) in the faces-config.xml file and specify a different version of the web.xml file (before 4.0), or simply do not add any of these configuration files. In my case, I removed the faces-config.xml and ran the application without problems.

I hope that the implementation of Mojarra will solve that little detail.