From the course: Java EE 8 Essential Training

JSF project setup - Java EE Tutorial

From the course: Java EE 8 Essential Training

Start my 1-month free trial

JSF project setup

- [Instructor] Let's get started with JSF by building out a new project in Eclipse. To do that, we can open the new dialog by pressing Control + N and then typing dynamic, and then we'll just select dynamic web project. Go ahead and hit Next, and this is going to open the next screen in the dialog, which will ask us for our project name. In this case, we're going to name the project hsports-catalog-jsf, and then we need to select some additional information. So make sure that we have the Wildfly runtime selected. We're using dynamic web module 4.0. And then here in the configuration, be sure to select JavaServer Faces v2.3 Project. That's going to cause Eclipse to configure our application as a JSF project. Next we will proceed in order to specify our source folders. I'm going to go ahead and switch these over to source main Java as well as source main resources. And we'll hit OK there and proceed in the dialog, and then we'll switch our content directory to source main web app. And then we just go ahead and hit Next. And then here's an important screen. This is asking us for the URL pattern that we would like to map the Faces servlet to. So every request matching the pattern will be routed through the Faces servlet so that it can conduct the JSF life cycle. Let's go ahead and remove the default pattern and we'll specify a new pattern. So this pattern's going to be asterisk .xhtml. So any URL that is ending with an xhtml extension will be routed through our Faces servlet. So we can go ahead and put that in place and then hit Finish, and that's going to create our new JSF project. What I'd like to do from here is add a facelet to our project. You'll remember facelets are the view technology that is used within JSF. So what we can do within the content directory, open up the New dialog and then type xhtml, and you'll see that we get some support here from JBoss and its tooling. So let's go ahead and hit Next, and it's going to ask us for the name of our new facelet. In this case, it's going to be form.xhtml. We can then go ahead and hit Next. And then if we would like, we can use a template. So we're going to use a template, but you'll see that we're going to modify it. So right now we're going to use the blank facelet page template. So just go ahead and hit Next there. And then we do not need to include any of these taglibs for the moment. And here we see our first facelet. Now, the thing that we're going to modify, you'll notice we're not using HTML5. So I'm going to go ahead and switch up this doctype, and that will cause us to use HTML5 instead of using an old doctype. And once we switch that over, we need to leverage some different tag libraries. So here you see the UI tag library for facelets. We're going to switch that out and just highlight that value and hit Control + Space, and you're going to see the new URIs for these different tag libraries. So make sure you switch them over to the jcp.org URL, because that's what it's been updated to. Sun hasn't been around for a while. And then we'll just go ahead and switch the core over, and then finally, we'll switch out the HTML tag library. Okay, so at this point we have our first facelets page. We'll work with this to build out our JSF application in the upcoming lessons.

Contents