1

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?

David Ferreira
  • 1,233
  • 17
  • 24
  • 1
    I personally always use a web.xml and faces-config.xml and put most recent versions in the 'header' but don't put any specific configurations things in there if I just use the defaults. In cases where you do not want to use defaults (e.g. running you application in JSF development mode) you add the things there. But keep in mind that MANY 'tutorials' are ancient (not completely wrong, but not up to date either). – Kukeltje May 24 '18 at 14:17
  • The linked duplicate comprehensively addresses the issue of when to use **faces-config.xml**, but does not even mention the other part of this question: _"In which cases should you continue to use the Web Deployment Descriptor-> web.xml"_. – skomisa Aug 28 '19 at 03:36

2 Answers2

1

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.

SCPhantom
  • 400
  • 3
  • 8
0

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.

David Ferreira
  • 1,233
  • 17
  • 24