Hello and welcome back.
In this video, I'm going to give you an overview of validating JSP forms.
We'll cover the following topics.
Well.
First, discuss the need for validation.
Then we'll look at the built in features of validation in JSF.
And then we'll take care of some housekeeping as far as creating a new Eclipse project for our validation
demo.
Now whenever you create an HTML form or a JSF form for that matter, you need to check the user input.
So when entering the data, you may have certain fields in your form that are required.
You also may have to validate the length of a field, say, for example, the number of digits in a
postal code, or validate the numbers and a range like you'll only accept the numbers of 1 to 50.
You may have to validate the format of data, like make sure it's a valid email address.
Finally, you may have your own custom business rule that you need to apply for validation.
Now the nice thing to know is that out of the box JSF has built in features for validation rules, so
everything that I discussed on the previous slide JSF has built in support.
So with JSF, you can check to make sure a field is required.
You can validate the length of a field.
You can also validate if it's a number or long in a given range.
You can also validate formatting by using regular expressions.
And finally there support for adding your own custom validation rule.
So all of these features are available in JSF.
Now let's discuss our road map.
So there's a lot of features for validation with JSF, and if I covered everything, it would take forever.
So I'm going to break it up into smaller videos.
I'll have one video and check in the required fields, the next one on validating length as far as the
range.
And then I'll cover how to validate using the regular expressions or reg x and then we'll wrap it up
with an example.
On doing custom validation.
So we'll break this up over multiple videos just so we have it available in nice bite sized chunks.
All right.
So let's go ahead and take care of some general housekeeping and the previous videos we may use of the
Hello World example.
And what I'd like to do instead here is create a new project that we can use for validation, and we'll
use it in all the all of the following videos.
So I'll actually show you how to create a new project for Validate demo.
All right.
So let's go ahead and move into Eclipse.
And what I like to do is create a new project.
So I'll go to file.
I'll say new dynamic web project.
And I'll create this new project named Validate Demo.
And then I'll move down and I'll set up the configuration here.
I'll click the modify button to modify the configuration.
I want to make sure I have support for JSF.
So over on the left hand side, make sure you check the box there right next to Java server faces.
I mean, you can go ahead and hit the okay button in the bottom right corner.
Now in this screen regarding our source folders, let's go ahead and make a modification here.
Let's go ahead and select the first item source main Java and let's remove this entry.
And now let's go ahead and click on Add folder and then we'll add the folder named Source.
I'm making this change here just to stay consistent with our existing videos.
All righty.
So that looks pretty good.
Let's go ahead and click on next.
And then for the content directory, I'll change that directory name to web content.
So again, staying consistent with our videos and also this is the directory name that was used in previous
versions of Eclipse.
So again, just staying consistent with what you'll see on Web projects.
All righty.
So that looks pretty good.
Let's go ahead and click on next.
Now for this section here for the JSF implementation library for the type, I'll choose the dropdown
and I'll choose disable library configuration because we'll do this manually later in the video.
I keep all the other defaults here for configuring the JSF servlet.
And down near the bottom.
This will allow us to access the JSF faces servlet by using interfaces prefix on our URL.
I'll go ahead and click on Finish.
And this will create a validate demo project for us that has support for JSF built in.
So right now our source directory is empty.
Our web content directory is empty except for our basic folders.
But now we have our very basic project in place.
And what we're going to do is we're going to make use of this validate demo project and all of the following
videos where we'll walk through examples of all the various validation roles.
Now there's still some additional steps that I need to do here.
I actually need to download the JSF libraries and add them to my project, and I'll show you how to
do that in a second.
So let's go ahead and open up a web browser and we're going to download those JSF jar files.
I'll simply go to love to code slash download JSF.
This will actually redirect you to the repository where you can download the JSF libraries.
All righty.
So we're here at the repository here for JSF.
Let's go ahead and scroll down on this list and I'll show you the actual file that you want to download.
So let me go ahead and zoom in here for a second.
You want to download the file Java X dot faces dash 2.2.8. jar.
That's the version of the Jar file that will work with this video series with no problems.
So you go and select that link, download it to your file system.
Your browser may prompt you and then you have the file.
Download it to your computer.
All right, so let's go to our file system in my downloads directory.
Here's the jar file that was just downloaded.
So let's go ahead and get this set up for our Eclipse project.
So we basically want to copy this to our Web live directory.
So I'll go ahead and copy that jar file from my file system.
I'll move over to Eclipse and I'll paste it into the directory web, EMF lib.
It's very important that you paste the jar file into a web and flip because that's a special class path
directory that your project will use.
And that's basically it.
So you've successfully downloaded the JSF Jar file and added it to your JSF project.
All right.
So this is just a short video here.
So in summary, what we did was we discussed the need for validation.
And then we also got an overview of the GSF validation features.
And then we went through and we took care of some housekeeping as far as creating our new Validate demo
project.
So this wraps up the video and validating JSF forms here.
I really just gave you an overview and as I mentioned earlier, I'm going to break up all these topics
in a separate videos.
And so we'll actually do a drill down or a deep dive into each one of those validation rules.
And I'll show you a complete example that works end to end with the validation.
So we have a lot of fun stuff in store, so stay tuned for the next set of validation videos.