4

I started on JSF2.0. I followed a tutorial with no problem and all worked fine! I used Eclipse Helios. But I noticed something I can not understand. The tutorial said to add Project Facet for JSF 2. I did no such thing and all worked ok. So to follow tutorial exactly I did:

Right-click on Project -> Properties -> Project Facets

And JavaServer Faces facet check-box was not ticked. I assume this is what the tutorial means by Project Facet. I clicked on it and a

Further Configuration Needed

link appeared. I followed the link to a JSF capabilities (Modify Faceted Project) dialog, I selected as User library, my library of JSF(which is MyFaces) but I got the error message:

Found multiple versions of the required class javax.faces.FactoryFinder.

What is this error? Can't I add project facet after creating my project? And what do I need the project facet for? My (trivial) code indicates that JSF works ok, so what is the project Facet useful for?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Cratylus
  • 52,998
  • 69
  • 209
  • 339
  • Problem with following IDE-centric tutorials is when the tutorial is for a different version of the IDE than the one you have. You should use an IDE-agnostic tutorial – Thorbjørn Ravn Andersen Dec 26 '10 at 10:17
  • @Thorbjørn Ravn Andersen: Tutorial uses Eclipse Helios and so do I – Cratylus Dec 26 '10 at 10:34
  • What tutorial did you use? I used one here, but got stuck when it says to find a file called faces-config.xml. There's no such a file in my project and I have no idea where to create it. – Gondim Dec 26 '10 at 13:31
  • @pringlesinn - faces-config.xml generally goes into the WAR's WEB-INF directory. I recommend getting a copy of the spec if you get stuck on details: http://jcp.org/en/jsr/detail?id=314 – McDowell Dec 26 '10 at 13:35
  • @pringlesinn:If you are using JSF2.0 the faces-config.xml is not needed if you use annotations.I am using the Marty Hall tutorials http://www.coreservlets.com/JSF-Tutorial/jsf2/ – Cratylus Dec 26 '10 at 14:56
  • Is there a JSF 4? Cause I think I got this.. – Gondim Dec 26 '10 at 17:16
  • @pringlesinn:Create a faces-config.xml and place it under WEB-INF along with web.xml.Leave it empty. If you have annotations in your beans it is not needed (in JSF2.0) so it can be empty. – Cratylus Dec 26 '10 at 20:03

3 Answers3

3

From the Eclipse help:

Facets define characteristics and requirements for Java EE projects and are used as part of the runtime configuration.

When you add a facet to a project, that project is configured to perform a certain task, fulfill certain requirements, or have certain characteristics. For example, the EAR facet sets up a project to function as an enterprise application by adding a deployment descriptor and setting up the project's classpath.

In the case of the JSF facet:

The following features are available when the JSF facet is installed:

  • JSF Library configuration support
  • Application Configuration Management
  • JSP Source Page semantic validation and content assist for most of the JSF Core and JSF HTML tag library attribute values using Expression Language (EL) or not.
  • "Run on Server" support of a JSF JSP page

In the case of this error:

Found multiple versions of the required class javax.faces.FactoryFinder.

It looks like the tooling has detected multiple copies of the core JSF API on the project classpath. JSF has some tolerance for this and has historically supported running different versions in different classloader contexts - that is, you can put one in the WAR and one in the container. Using the Open Type dialog (CTRL+SHIFT+T) and searching for javax.faces.FactoryFinder should help you locate the culprit jar.

McDowell
  • 107,573
  • 31
  • 204
  • 267
  • 2
    Also, there's a "visual" faces-config.xml editor. Not that this is very useful in JSF 2.0 since almost everything can be done by annotations :) – BalusC Dec 26 '10 at 13:58
  • Doing the ctrl+shift+T I found that `javax.faces.FactoryFinder` was included by my-faces-api.jar and my-faces-bundle.jar. I removed bundle and error was resolved! After doing it, I see that the web.xml was modified with extra definitions and a faces-config.xml was added. So I guess extra things I would have to do manually was added via the facet. Thanks! – Cratylus Dec 26 '10 at 15:07
  • @BalusC:I see that the faces-config.xml editor has some kind of designer which it seems is to show navigation links graphically. Isn't this feature useful? Also is it available if you use annotations? – Cratylus Dec 26 '10 at 15:11
  • 1
    Yes it is. I have however never used it. I tend to hate visual editors in general and I like to control it myself at code level. The only advangage that the JSF facet offers for me is that it puts the right JAR's in the `WEB-INF/lib` and autogenerates faces-config.xml for me :) – BalusC Dec 26 '10 at 15:23
2

Adding the JSF nature/facet to your project adds abilities like code completion, adding jsf visual components to your web page editor etc to your project. Check your build patch and see how many jsf api jars are there. I am assuming this error is in the IDE and not in the running app.

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • At my build path is my user library that contains all of jars of MyFaces. I can open *.xhtml files via web editor and I get for these files the various tags. I do not see what I am missing without the JSF ticked in project facets – Cratylus Dec 26 '10 at 09:36
0

The JSF facet helps you to property configure your project with JSF libraries. It also enables a bunch of JSF specific validation and tools from the JSF Tools project. While it certainly possible to develop a JSF app without using JSF tools like you have done, you can be more productive if you are using these tools.

If you are interested in trying out JSF tools with your tutorial, start out by creating a new web project with JSF facet. Then skip the parts of your tutorial that talk about configuring libraries or creating descriptors.

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
  • I created a project with the JSF facet, but no libs were added under WEB-INF\lib. I had to add them manually. Why is this? – Cratylus Dec 30 '10 at 13:00
  • There are many ways to add JSF libraries to a project and most of them don't involve adding jars physically to WEB-INF/lib in source code. They are typically remotely referenced and are only packaged into WEB-INF/lib when project is exported as an archived or published. – Konstantin Komissarchik Dec 30 '10 at 17:17