﻿WEBVTT

1
00:00:01.149 --> 00:00:02.543
<v Instructor>Hey, welcome back.</v>

2
00:00:02.543 --> 00:00:03.980
In this video, I'm gonna show you

3
00:00:03.980 --> 00:00:08.147
how to update a student in the database using JSF.

4
00:00:10.043 --> 00:00:11.872
We'll cover the following topics.

5
00:00:11.872 --> 00:00:14.644
We'll first start off with a demo of the application,

6
00:00:14.644 --> 00:00:17.875
then we'll take a step back, look at the big picture,

7
00:00:17.875 --> 00:00:21.624
then we'll drill down a bit, look at the sequence diagram,

8
00:00:21.624 --> 00:00:22.868
and then we'll get our hands dirty,

9
00:00:22.868 --> 00:00:25.298
and we'll do a full code walkthrough.

10
00:00:25.298 --> 00:00:26.568
So, for the code walkthrough,

11
00:00:26.568 --> 00:00:28.662
we'll break it up into two separate videos.

12
00:00:28.662 --> 00:00:31.579
So, let's go ahead and get started.

13
00:00:33.137 --> 00:00:35.340
So, here's a demo of the application.

14
00:00:35.340 --> 00:00:37.499
So, we have our FooBar University.

15
00:00:37.499 --> 00:00:39.810
Up in the top left, we have the Add Student button

16
00:00:39.810 --> 00:00:41.810
from the previous video.

17
00:00:44.067 --> 00:00:46.569
Then we're gonna add this new column over on the far right,

18
00:00:46.569 --> 00:00:48.259
called Action, and it's gonna have these links

19
00:00:48.259 --> 00:00:49.926
to update a student.

20
00:00:53.704 --> 00:00:55.031
So, we can choose one of those links.

21
00:00:55.031 --> 00:00:56.229
It'll take us directly to the page

22
00:00:56.229 --> 00:00:57.599
and we can update a student.

23
00:00:57.599 --> 00:01:02.453
It's already prepopulated with that student's information.

24
00:01:02.453 --> 00:01:04.557
So, for this student, Lisa Astor, I can go through

25
00:01:04.557 --> 00:01:06.059
and maybe change her name.

26
00:01:06.059 --> 00:01:07.820
Say, for example, she got married

27
00:01:07.820 --> 00:01:10.153
and she has a new last name.

28
00:01:11.522 --> 00:01:14.212
So, her new last name is Mangano.

29
00:01:14.212 --> 00:01:17.297
And, also, she chose to change her email address.

30
00:01:17.297 --> 00:01:20.880
She's pretty funny, so funnylisa@gmail.com.

31
00:01:24.337 --> 00:01:25.709
Alright, great, so this all looks good.

32
00:01:25.709 --> 00:01:27.415
So, we've updated her email address

33
00:01:27.415 --> 00:01:30.665
and, also, we've updated her last name.

34
00:01:31.787 --> 00:01:33.114
And so I can go ahead and hit Save

35
00:01:33.114 --> 00:01:37.197
and this will actually update it in the database.

36
00:01:38.290 --> 00:01:40.183
Okay, great, so let's look at the list.

37
00:01:40.183 --> 00:01:43.499
Right here is Lisa and her new name, Mangano.

38
00:01:43.499 --> 00:01:46.347
Again, everything's being sorted by last name.

39
00:01:46.347 --> 00:01:48.238
And, also, here's her new email address.

40
00:01:48.238 --> 00:01:49.314
So, this works great.

41
00:01:49.314 --> 00:01:52.490
So, we were successful in updating a given student

42
00:01:52.490 --> 00:01:54.138
and changing their information

43
00:01:54.138 --> 00:01:57.754
and seeing those results reflected here on the screen.

44
00:01:57.754 --> 00:02:01.127
So, what I'll do is I'll actually take you through the code

45
00:02:01.127 --> 00:02:03.529
step by step on how all of this works.

46
00:02:03.529 --> 00:02:05.304
But before we get into the code,

47
00:02:05.304 --> 00:02:09.471
let's go ahead and step back and look at the big picture.

48
00:02:11.802 --> 00:02:13.841
Alright, so here's the big picture.

49
00:02:13.841 --> 00:02:17.402
So, up in the top left, we have this list-students.xhtml.

50
00:02:17.402 --> 00:02:19.169
That's the page that you just saw.

51
00:02:19.169 --> 00:02:21.118
There's new links along the right hand side

52
00:02:21.118 --> 00:02:24.575
for action links for updating the student.

53
00:02:24.575 --> 00:02:25.607
That action link will take you

54
00:02:25.607 --> 00:02:28.735
to the update-student-form.xhtml.

55
00:02:28.735 --> 00:02:30.713
This form is gonna be prepopulated

56
00:02:30.713 --> 00:02:32.547
with that student's information.

57
00:02:32.547 --> 00:02:35.148
So, again, you go through and modify the information,

58
00:02:35.148 --> 00:02:36.971
hit Save, then that'll take us over

59
00:02:36.971 --> 00:02:38.673
to the Student Controller.

60
00:02:38.673 --> 00:02:40.028
That's our managed theme.

61
00:02:40.028 --> 00:02:42.335
This will actually update the user

62
00:02:42.335 --> 00:02:45.344
by calling our Student DbUtil.

63
00:02:45.344 --> 00:02:48.639
So, the Student DbUtil handles updating the information

64
00:02:48.639 --> 00:02:49.972
in the database.

65
00:02:51.052 --> 00:02:53.099
Now, a little bit more about this Update link here.

66
00:02:53.099 --> 00:02:56.161
So, each row will have a Update link.

67
00:02:56.161 --> 00:03:00.088
So, this Update link actually has the current student ID

68
00:03:00.088 --> 00:03:01.345
embedded in the link,

69
00:03:01.345 --> 00:03:03.327
just so we know which student to update.

70
00:03:03.327 --> 00:03:05.114
Now, when you click this link,

71
00:03:05.114 --> 00:03:07.567
it'll basically go to the database,

72
00:03:07.567 --> 00:03:09.640
load that student from the database,

73
00:03:09.640 --> 00:03:11.652
and have that student in memory,

74
00:03:11.652 --> 00:03:14.367
and it'll use that to prepopulate the form

75
00:03:14.367 --> 00:03:16.695
that will show to the user.

76
00:03:16.695 --> 00:03:18.060
And I'll actually take you through all the steps

77
00:03:18.060 --> 00:03:20.938
on how the prepopulating of the form works out.

78
00:03:20.938 --> 00:03:24.188
We'll see that in the code walkthrough.

79
00:03:27.447 --> 00:03:29.322
Alright, great, so once we've loaded the student,

80
00:03:29.322 --> 00:03:30.760
we've prepopulated the form,

81
00:03:30.760 --> 00:03:33.333
so our update-student-form.xhtml,

82
00:03:33.333 --> 00:03:35.107
they go through and modify information in the form,

83
00:03:35.107 --> 00:03:36.725
they hit the Save button.

84
00:03:36.725 --> 00:03:38.333
So, what this will do is this will actually call

85
00:03:38.333 --> 00:03:41.262
the Student Controller, it'll call the update student method

86
00:03:41.262 --> 00:03:43.707
on the controller, which is our managed theme,

87
00:03:43.707 --> 00:03:45.491
and then the controller will delegate that call

88
00:03:45.491 --> 00:03:47.427
off to the student database util

89
00:03:47.427 --> 00:03:51.260
which will actually update it in the database.

