Instructor: Hey, welcome back.
In this video, I'm gonna show you
how to update a student in the database using JSF.
We'll cover the following topics.
We'll first start off with a demo of the application,
then we'll take a step back, look at the big picture,
then we'll drill down a bit, look at the sequence diagram,
and then we'll get our hands dirty,
and we'll do a full code walkthrough.
So, for the code walkthrough,
we'll break it up into two separate videos.
So, let's go ahead and get started.
So, here's a demo of the application.
So, we have our FooBar University.
Up in the top left, we have the Add Student button
from the previous video.
Then we're gonna add this new column over on the far right,
called Action, and it's gonna have these links
to update a student.
So, we can choose one of those links.
It'll take us directly to the page
and we can update a student.
It's already prepopulated with that student's information.
So, for this student, Lisa Astor, I can go through
and maybe change her name.
Say, for example, she got married
and she has a new last name.
So, her new last name is Mangano.
And, also, she chose to change her email address.
She's pretty funny, so funnylisa@gmail.com.
Alright, great, so this all looks good.
So, we've updated her email address
and, also, we've updated her last name.
And so I can go ahead and hit Save
and this will actually update it in the database.
Okay, great, so let's look at the list.
Right here is Lisa and her new name, Mangano.
Again, everything's being sorted by last name.
And, also, here's her new email address.
So, this works great.
So, we were successful in updating a given student
and changing their information
and seeing those results reflected here on the screen.
So, what I'll do is I'll actually take you through the code
step by step on how all of this works.
But before we get into the code,
let's go ahead and step back and look at the big picture.
Alright, so here's the big picture.
So, up in the top left, we have this list-students.xhtml.
That's the page that you just saw.
There's new links along the right hand side
for action links for updating the student.
That action link will take you
to the update-student-form.xhtml.
This form is gonna be prepopulated
with that student's information.
So, again, you go through and modify the information,
hit Save, then that'll take us over
to the Student Controller.
That's our managed theme.
This will actually update the user
by calling our Student DbUtil.
So, the Student DbUtil handles updating the information
in the database.
Now, a little bit more about this Update link here.
So, each row will have a Update link.
So, this Update link actually has the current student ID
embedded in the link,
just so we know which student to update.
Now, when you click this link,
it'll basically go to the database,
load that student from the database,
and have that student in memory,
and it'll use that to prepopulate the form
that will show to the user.
And I'll actually take you through all the steps
on how the prepopulating of the form works out.
We'll see that in the code walkthrough.
Alright, great, so once we've loaded the student,
we've prepopulated the form,
so our update-student-form.xhtml,
they go through and modify information in the form,
they hit the Save button.
So, what this will do is this will actually call
the Student Controller, it'll call the update student method
on the controller, which is our managed theme,
and then the controller will delegate that call
off to the student database util
which will actually update it in the database.