Voiceover: Hey, welcome back.
In this video, we're gonna cover part two
of JSF forms and drop-down lists.
What we're gonna do in this example
is that we're gonna enhance
the previous video example.
Instead of having the drop-down list values
hard coded in the JSF page,
what we're gonna do instead is
read the values from a managed bean.
So, make the application a bit more dynamic.
So let's go ahead and move into Eclipse.
Again, we're gonna continue with the same project as before,
Hello Project.
I'm gonna edit the file studenttwo.java.
So this is our managed bean from the previous video,
and what I'm gonna do here is
I'm gonna update the managed bean
to contain a list of options.
So this'll be the list of countries
that a user can select.
So I'll just do an import here
for the type list.
And so this is a list of our country options.
Now, what we need to do next
is populate this list with some data.
So the first thing I'll do is I'll construct the list,
inside of the constructor,
so I'll say country options = new Array List,
and then I'll go through and fix the import here
for Array List.
This is java.util.arraylist.
And then I need to just drop in
the list of options here.
So I'm gonna drop in some code that I already have.
And so, I have this array list of strings,
and I'm gonna simply add in the various countries.
Brazil, France, Germany, India, and so on.
Now, the next thing I need to do
is actually create a getter method
for that list of country options.
So, again, I'll make use of that Eclipse trick,
where I'll do a right click,
I'll choose source,
I'll move down to generate getters and setters.
And in the box here,
I'll expand the list here for country options,
and I'll select the option for get country options.
I really only need a getter here,
I don't need a setter.
And then, as far as the placement of this getter,
I'll place it right after the After Student Two,
so right after the constructor for this class.
That's the actual insertion point.
And then I'll hit okay.
And so, on lines 39 down to 41,
this is the new code that Eclipse just entered for us.
So it's a public getter method for country options,
and it's gonna return the array list,
I'm sorry, return the list of strings
to the calling program.
Alright, so this looks really good right now.
I'll do some quick clean up here.
And, great. So we're in really good shape right now
with this addition to the managed bean.
Well, the next thing I need to do
is update my form.
So I need to up down the drop-down list,
so instead of having a hard code of values,
I need to make use of that managed bean.
So I'll move into the code that I had before,
from the previous video,
and I will simply
select all of the code that was hard coded,
and I'll actually remove it or delete it from this file.
And instead what I'll do is I'll drop in some new code.
So, right now, select one menu value,
studenttwo.country,
that's the same.
This is the important line here.
So here's select items, plural,
and I have value, pound, curly brace,
studenttwo.countryoptions.
So, when this page is loaded,
JSF will actually call studenttwo.getcountryoptions.
So it's gonna return that list of strings
that we've already defined
inside of that managed bean class.
So this is how we can get the list of options
from the managed bean,
as opposed to hard coding it in the JSF page.
Now I just ran the application,
and here's the output.
So we have our first name, last name.
So I'll enter Ajay Rao, again.
And then for country.
So now this country drop-down list
is being populated by information
from our managed bean.
So it's no longer being hard coded in the JSF page,
but that data's coming from our managed bean.
I'm going to hit submit,
and here we list the student's country,
of India,
networks out as desired.
So in this part of it, nothing's really changed
as far as the confirmation page.
Alright, so this looks really good.
Good job.
Okay, so this wraps up the video.
In this video we learned how to use JSF forms
and drop-down lists.
In particular, we enhanced our previous example
to make use of managed themes for the form data.
So instead of using the hard coded data
in the JSF page,
we actually have the data being pulled
from a managed bean.