📺 Develpreneur YouTube Episode

Video + transcript

Spring Boot - JavaScript Hide On Click

2024-02-20 •Youtube

Detailed Notes

We are continuing a series of tutorials focused on Spring Boot. The crux of the project is to convert/migrate an old JSP/Tomcat application to a modern Spring Boot application and Java 7/8 to a current version. This short shows us hiding rows and deleting data in a smooth view to the user.

You can learn more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list, and you will periodically receive coupons for courses and notifications of the latest releases.

Transcript Text
[Music]
well hello and welcome back we are
continuing walking through our project
we were converting an old uh JSP Tomcat
application to a new fangled spring Boot
and uh
using that to get our application going
we've worked through some CSS and
cleaned some stuff a little bit up a
little bit here and there we're going to
continue doing some of that kind of work
this time not CSS actually what I want
to do is uh we're going to do some some
quick uh re like quick function type
things now what we would see one of the
things we end up
doing is if we come over here to
Opportunities one of the things we want
to do is we want to be able to like
click on one besides just deleting it or
looking at the
details we want to be able to basically
take one and say hey I'm going to copy
it over it's going to basically now be a
project it basically and it would make
sense I have a proposal I'm G to go
ahead and fire off that proposal so I
want to store that as a project but
right now first uh one I'm going to fix
this thing whoop that um has these
things unlined weird and uh also what
we're going to do is we're going to put
a button here this is going to allow us
instead of having to step into our
project and set it to uh like here let's
say lost or cancelled and doing a save
update we're going to have a couple
buttons and probably it's going to be
something along the lines of
uh let's just say lost we'll do a lost
button here uh we probably could do
within that uh we might do a one as well
or a cancel but let's do one and loss
those probably the quickest ones that
would make sense if I'm going through
projects that I'm going to say Hey you
know I want it or I lost it um lost is
probably first so what we want to do is
we're going to go to each of these now
we are going to have a bit of an issue
CU When we click on it we've already got
that div so that it's jumping out there
so so we're going to have to change some
stuff around a little bit here in order
to make our button work otherwise we'll
click on this when we click on the
button it's going to take it as this
click and we're probably going to get
into some weird stuff so what we're also
going to do is we're going to change
this to an edit so let's go back over to
our
code and what we want to do is we want
to go find the uh this going to be list
projects I do
believe uh it's probably projects and if
we look there yeah so we have name
status uh here we go maintain overhead
oh is that yeah maintain overhead
maintain difficulty uh these I think we
still have to hook up at some point
we'll get to those and so in
here here's the first thing we have uh
here we have this onclick and it's going
to do select project so what we need to
do
instead is we're going to need to change
this so that this on click is actually
going to be a button and so we probably
want to do is we've got all these we've
got this fix created so we're going to
do is we're going to do
actions and we're going to call it that
let's see 2 4 6 7 10 so we can just
let's go ahead and fill this out because
we've got space out
here uh this is oh that's where our
problem is is that we've got uh name
name status and label are a two but then
our fixed is a two there instead of a
one so if we do that we make our created
three and then we're going to have our
buttons
here and that's going to be a
two and what we want to do
here is we're going to have two buttons
and so the first one uh let's go ahead
and we're just going to make them a div
cuz we're going to keep it that simple
uh and then it's going to do an onclick
here and so that's our first one oh the
class is going to be uh
button and what did we have those other
buttons those were a button primary so
let's keep
those uh let's I think we had a
different let's do like button info
button name button info if you can
remember from our bootstrap uh
work and so for this uh there's my class
I'm going to select the project I'm
using the project ID I want to get rid
of this because I don't want to click on
the
div and I'm going to say
edit and so let's take a look at what
that looks like so if we come in here we
restart this let's just start with
that and what this should do now now is
when I log
in when I log
[Music]
in then it's not showing it okay so did
I get the right page that could be the
problem there it is okay so I am on the
projects edit uh the homepage is a
little different so we'll have to fix
that one when we get to it so we go in
here and it's an edit but it doesn't
like to treat that as a
button uh so if I look here oh well
first let's make sure if I click on it
it's not editing if I click here oh it's
probably because of it's background if I
click on that now it comes in so let's
make it do I have a
different well let's just look at it
real quick because we can we can come in
here and that button info instead let's
make it uh what did we say before that
was so let's make it button
primary if we do that doesn't really
work oh probably oh that's going to be
interesting button primary let's make it
button
secondary doesn't like that
either oh because I didn't say class
funny how when you do it like there we
go typos will do that to you uh what did
I say button default is what I
originally
[Music]
had um not a big fan of default
necessarily on that
uh what's that
button uh let's just say
button
info info probably works okay uh it's
not super awesome though because of
where it's at so let's play with that
just a tad so what we're going to do is
that has to be a class and let's go
ahead and put this
inside a
container cuz I think that may wrap
those buttons up a little bit this is
where we're getting a little bit clui
and how we're doing stuff we could
actually clean up those buttons but I'm
not going to right now because then the
other thing I'm going to
do is I'm going to
have and I'm just going to put a spa I'm
going to put two spaces between it let's
do that
mbsp and mbsp which is a space so
there's two spaces and then this one's
going to be um I'm going to say lost and
and we're just going to say lost
project and it's going to be the project
ID and so up here where we do uh we do
select we're going to change this around
a little bit because what we want to do
here is what we'll probably cover in the
next episode because we're going to get
go into part two of this what we're
going to want to do here is we're not
going to want to just go out and then
come back what we're going to want to do
is we're going to call something and
we'll call it um
let's just say lost project and it's
going to have an ID so we're going to
have to create this but we want to do
instead of window location and actually
changing our URL we're going to come in
and we're going to use an Ajax call and
so we're just going to fire that off and
then one of the things we're going to
have to do so we're going to say here
there will be uh Ajax call to Mark lost
and then we're going to have something
that is going to be uh hide the
row
and so because we're going to hide the
row and actually let's start with that
right now instead of making it
lost what we're going to
do is we're going to go in
here and does this have a that does not
have an
ID so we can
say uh let's do I wonder if we can do
that let's do th name uh let's do th ID
equals and let's see if it'll do that oh
that's
within what we want to do is we want to
take that so it's going to be uh that's
going to be the project. ID let's do
that and let's see if that will work I
haven't actually tried that with
the uh let's see oh let's do double
quotes and let's see if that will
generate that because then what I'm
going to want to do is I'm going to come
up here and I'm going to do something to
make sure that I know which row I'm on
which is basically going to be uh
document. getet
element there we go uh by ID and we're
going to give it the ID which is going
to be the same as the ID that we passed
in it's the project
ID and then we're going to do doc uh
oops that's going to be uh let's just
say control equals
that and then we're going to do
control.
[Music]
display
equals
none and I think it'll work like that
and we're going to find out in a
minute so I think if we do it like that
that'll give us to us but let's check a
couple of these things out and let's see
what we did with our buttons did we
clean that up a little
bit if we go here
whoops there we go if we log
in and we go to our projects let me
close this out so now we have okay so we
have edit and lost and look so those
look a little bit better there if we do
lost it does nothing
because uh let's go look at that so if
it says on CL click okay so uh where's
our
row so if we go up to that's our
button here's our header wait uh there
we go so it does give us our ID so
that's cool so we got our ID coming in
and then if we go to lost and and we say
lost uh lost project it didn't like it
because oh control display is none and
that's probably not the way to do
it uh actually I think it is called
style let me go check that real quick
I'm back and it is dot do style.
display and then it is lowercase so now
if we do that
that we have if we come in
here we now should have that we have
taken
our single click rows and now we've got
buttons on
them and if we click on row it doesn't
do anything if we click on the edit it
edits and if we click on lost it does
nothing and so let's see what that
complains
about uh let's see evaluating control
style uh null is not an object oh so
let's see on
click uh the ID is let's do it like this
um because I may not like that number
let's make our ID equal to uh let's call
it row
underscore I think it'll work like that
I think we'll just uh actually no it's
going to we need to push that together a
little bit so we want to
do uh we want to do it like this I
believe we just want to do row
underscore and then here when we do by
ID Oh shoot that's why it's going to be
row
underscore plus ID let's try that
probably would have worked the way we
had it but when you put comments uh
quotes in the wrong places those things
happen so let's take a look at
it come back over here let's go fire it
up let's Lo log in let's go to our
projects let's try to hit lost and there
now stuff disappears but it's not doing
anything else so I can come in here and
I can go lost and lose all of them but
if I reset it if I refresh it boom it
comes back so next thing we want to do
is we're going to create our little uh
endpoint essentially our function that
we're going to be able to call and it's
going to go in it's basically going to
take that project it's going to edit it
uh its status and then it's going to go
ahead and disappear it so that is what
we're going to come back to next time uh
as always if you have any questions
shoot us an email at info developer.com
we're just looking for ways to you know
sort of share what we've learned and
help you guys get developers get to be
better developers and we're more than
happy to uh have some suggestions and
recommendations from you as well that
being said go out there and have
yourself a great day a great week and we
will talk to you next
time
three
two one hello this is Rob with develop
andur also known as building better
developers wanted to announce that we
have school. developin or.com feel free
to check it out if you like any of this
information any of the content that
we've sent and you would like to see
more you can come out you can enroll for
free we have free courses we've got
places for you to get better at just
learning a technology or how toos you
can work on your business skills we can
help you with becoming a better
developer as in coding and things like
that a lot of the stuff you've seen on
YouTube we also have out at school.
develop andure we just have it in a
little more of a educational format and
a way for you to track your progress as
you move forward becoming a better
developer
Transcript Segments
0.64

[Music]

6.48

well hello and welcome back we are

9.08

continuing walking through our project

11.28

we were converting an old uh JSP Tomcat

15.2

application to a new fangled spring Boot

18.199

and uh

19.24

using that to get our application going

21.72

we've worked through some CSS and

23.359

cleaned some stuff a little bit up a

24.72

little bit here and there we're going to

26.199

continue doing some of that kind of work

28.599

this time not CSS actually what I want

30.679

to do is uh we're going to do some some

33.76

quick uh re like quick function type

37.44

things now what we would see one of the

39.16

things we end up

40.559

doing is if we come over here to

42.36

Opportunities one of the things we want

43.48

to do is we want to be able to like

45.44

click on one besides just deleting it or

47.239

looking at the

48.32

details we want to be able to basically

50.36

take one and say hey I'm going to copy

51.84

it over it's going to basically now be a

54.76

project it basically and it would make

56.84

sense I have a proposal I'm G to go

59.399

ahead and fire off that proposal so I

61.559

want to store that as a project but

64

right now first uh one I'm going to fix

66.4

this thing whoop that um has these

70

things unlined weird and uh also what

73.479

we're going to do is we're going to put

74.24

a button here this is going to allow us

76.159

instead of having to step into our

78.479

project and set it to uh like here let's

82

say lost or cancelled and doing a save

84.92

update we're going to have a couple

86.36

buttons and probably it's going to be

87.88

something along the lines of

90.6

uh let's just say lost we'll do a lost

92.84

button here uh we probably could do

95.68

within that uh we might do a one as well

99.079

or a cancel but let's do one and loss

101.759

those probably the quickest ones that

103.28

would make sense if I'm going through

104.759

projects that I'm going to say Hey you

106.6

know I want it or I lost it um lost is

109.6

probably first so what we want to do is

112.36

we're going to go to each of these now

113.52

we are going to have a bit of an issue

115.439

CU When we click on it we've already got

117.64

that div so that it's jumping out there

119.64

so so we're going to have to change some

121.24

stuff around a little bit here in order

123.159

to make our button work otherwise we'll

125.96

click on this when we click on the

127.6

button it's going to take it as this

128.8

click and we're probably going to get

130.239

into some weird stuff so what we're also

133.12

going to do is we're going to change

134.36

this to an edit so let's go back over to

136.8

our

138

code and what we want to do is we want

140.04

to go find the uh this going to be list

144

projects I do

146.76

believe uh it's probably projects and if

150.08

we look there yeah so we have name

153.319

status uh here we go maintain overhead

155.76

oh is that yeah maintain overhead

158.76

maintain difficulty uh these I think we

160.92

still have to hook up at some point

162.64

we'll get to those and so in

168.08

here here's the first thing we have uh

172.92

here we have this onclick and it's going

175.159

to do select project so what we need to

177.519

do

178.4

instead is we're going to need to change

181.04

this so that this on click is actually

184.599

going to be a button and so we probably

186.959

want to do is we've got all these we've

188.879

got this fix created so we're going to

190.28

do is we're going to do

195.76

actions and we're going to call it that

198.12

let's see 2 4 6 7 10 so we can just

201.599

let's go ahead and fill this out because

203.319

we've got space out

205.2

here uh this is oh that's where our

207.44

problem is is that we've got uh name

209.799

name status and label are a two but then

213.879

our fixed is a two there instead of a

216.68

one so if we do that we make our created

218.92

three and then we're going to have our

220.799

buttons

222.239

here and that's going to be a

224.84

two and what we want to do

230.239

here is we're going to have two buttons

232.72

and so the first one uh let's go ahead

236.239

and we're just going to make them a div

238.84

cuz we're going to keep it that simple

241.36

uh and then it's going to do an onclick

248.799

here and so that's our first one oh the

252.76

class is going to be uh

256.479

button and what did we have those other

259.04

buttons those were a button primary so

261.44

let's keep

263.44

those uh let's I think we had a

266.68

different let's do like button info

269.16

button name button info if you can

270.8

remember from our bootstrap uh

273.44

work and so for this uh there's my class

276.96

I'm going to select the project I'm

278.72

using the project ID I want to get rid

281.16

of this because I don't want to click on

283.24

the

285.08

div and I'm going to say

288.84

edit and so let's take a look at what

290.96

that looks like so if we come in here we

293.16

restart this let's just start with

297.4

that and what this should do now now is

300.8

when I log

302.44

in when I log

304.33

[Music]

305.56

in then it's not showing it okay so did

308.72

I get the right page that could be the

311.16

problem there it is okay so I am on the

315

projects edit uh the homepage is a

316.96

little different so we'll have to fix

318.16

that one when we get to it so we go in

320.16

here and it's an edit but it doesn't

322.36

like to treat that as a

325.479

button uh so if I look here oh well

329.199

first let's make sure if I click on it

331.36

it's not editing if I click here oh it's

333.52

probably because of it's background if I

335.12

click on that now it comes in so let's

338

make it do I have a

341.96

different well let's just look at it

344.12

real quick because we can we can come in

347.319

here and that button info instead let's

351

make it uh what did we say before that

353.72

was so let's make it button

357.479

primary if we do that doesn't really

360

work oh probably oh that's going to be

361.8

interesting button primary let's make it

363.8

button

367.72

secondary doesn't like that

370.96

either oh because I didn't say class

374.52

funny how when you do it like there we

377.28

go typos will do that to you uh what did

380.36

I say button default is what I

381.96

originally

382.75

[Music]

384.12

had um not a big fan of default

387

necessarily on that

390.199

uh what's that

391.919

button uh let's just say

394.599

button

397.12

info info probably works okay uh it's

401.44

not super awesome though because of

403.56

where it's at so let's play with that

405.12

just a tad so what we're going to do is

407.8

that has to be a class and let's go

409.8

ahead and put this

411.479

inside a

415.68

container cuz I think that may wrap

419.16

those buttons up a little bit this is

421.36

where we're getting a little bit clui

422.759

and how we're doing stuff we could

424.479

actually clean up those buttons but I'm

426.08

not going to right now because then the

428.16

other thing I'm going to

429.599

do is I'm going to

434.12

have and I'm just going to put a spa I'm

436.319

going to put two spaces between it let's

437.879

do that

439.16

mbsp and mbsp which is a space so

442.479

there's two spaces and then this one's

444.56

going to be um I'm going to say lost and

449.4

and we're just going to say lost

452

project and it's going to be the project

454.039

ID and so up here where we do uh we do

458.12

select we're going to change this around

460.08

a little bit because what we want to do

463.12

here is what we'll probably cover in the

465.96

next episode because we're going to get

467.36

go into part two of this what we're

468.879

going to want to do here is we're not

470.36

going to want to just go out and then

472.84

come back what we're going to want to do

475.8

is we're going to call something and

477.199

we'll call it um

479.919

let's just say lost project and it's

482.159

going to have an ID so we're going to

483.28

have to create this but we want to do

485.44

instead of window location and actually

488.08

changing our URL we're going to come in

489.8

and we're going to use an Ajax call and

492

so we're just going to fire that off and

494.199

then one of the things we're going to

495.159

have to do so we're going to say here

497.039

there will be uh Ajax call to Mark lost

502.879

and then we're going to have something

505.36

that is going to be uh hide the

508.24

row

510.44

and so because we're going to hide the

511.56

row and actually let's start with that

513.56

right now instead of making it

515.399

lost what we're going to

517.56

do is we're going to go in

521.08

here and does this have a that does not

523.88

have an

526.56

ID so we can

528.88

say uh let's do I wonder if we can do

532.08

that let's do th name uh let's do th ID

537.399

equals and let's see if it'll do that oh

539.8

that's

540.64

within what we want to do is we want to

542.839

take that so it's going to be uh that's

546.2

going to be the project. ID let's do

550.44

that and let's see if that will work I

553.36

haven't actually tried that with

555.839

the uh let's see oh let's do double

560.48

quotes and let's see if that will

562.8

generate that because then what I'm

564.16

going to want to do is I'm going to come

565.399

up here and I'm going to do something to

568.36

make sure that I know which row I'm on

570.279

which is basically going to be uh

572.72

document. getet

574.76

element there we go uh by ID and we're

578.68

going to give it the ID which is going

580.399

to be the same as the ID that we passed

582.76

in it's the project

584.48

ID and then we're going to do doc uh

587.16

oops that's going to be uh let's just

589.88

say control equals

592.44

that and then we're going to do

595.04

control.

596.46

[Music]

598.12

display

602.6

equals

604.44

none and I think it'll work like that

606.72

and we're going to find out in a

608.24

minute so I think if we do it like that

610.88

that'll give us to us but let's check a

612.279

couple of these things out and let's see

614.32

what we did with our buttons did we

616.88

clean that up a little

618.56

bit if we go here

622.24

whoops there we go if we log

625.36

in and we go to our projects let me

628.04

close this out so now we have okay so we

630.399

have edit and lost and look so those

631.64

look a little bit better there if we do

634

lost it does nothing

638.24

because uh let's go look at that so if

640.399

it says on CL click okay so uh where's

643.36

our

644.279

row so if we go up to that's our

647.6

button here's our header wait uh there

651.48

we go so it does give us our ID so

654.16

that's cool so we got our ID coming in

657.36

and then if we go to lost and and we say

660.079

lost uh lost project it didn't like it

664.279

because oh control display is none and

667.24

that's probably not the way to do

672.68

it uh actually I think it is called

675.56

style let me go check that real quick

678.88

I'm back and it is dot do style.

684.6

display and then it is lowercase so now

688.48

if we do that

692.24

that we have if we come in

696.48

here we now should have that we have

699.2

taken

700.959

our single click rows and now we've got

703.639

buttons on

705.24

them and if we click on row it doesn't

707.48

do anything if we click on the edit it

709.6

edits and if we click on lost it does

713

nothing and so let's see what that

715

complains

717.68

about uh let's see evaluating control

720.519

style uh null is not an object oh so

724.56

let's see on

727.12

click uh the ID is let's do it like this

730.639

um because I may not like that number

733.639

let's make our ID equal to uh let's call

737

it row

738.04

underscore I think it'll work like that

740.24

I think we'll just uh actually no it's

742.199

going to we need to push that together a

745.24

little bit so we want to

747.88

do uh we want to do it like this I

751.16

believe we just want to do row

754.639

underscore and then here when we do by

758

ID Oh shoot that's why it's going to be

762.6

row

764.24

underscore plus ID let's try that

767.639

probably would have worked the way we

768.6

had it but when you put comments uh

770.32

quotes in the wrong places those things

772.04

happen so let's take a look at

774.32

it come back over here let's go fire it

777.519

up let's Lo log in let's go to our

781.199

projects let's try to hit lost and there

784.199

now stuff disappears but it's not doing

786.36

anything else so I can come in here and

788.24

I can go lost and lose all of them but

790.6

if I reset it if I refresh it boom it

793.279

comes back so next thing we want to do

795.519

is we're going to create our little uh

797.8

endpoint essentially our function that

800.04

we're going to be able to call and it's

801.88

going to go in it's basically going to

803.32

take that project it's going to edit it

805.839

uh its status and then it's going to go

808.12

ahead and disappear it so that is what

811.04

we're going to come back to next time uh

813.12

as always if you have any questions

814.639

shoot us an email at info developer.com

816.92

we're just looking for ways to you know

818.839

sort of share what we've learned and

820.44

help you guys get developers get to be

822.32

better developers and we're more than

823.88

happy to uh have some suggestions and

826.079

recommendations from you as well that

828.32

being said go out there and have

829.48

yourself a great day a great week and we

831.68

will talk to you next

837.759

time

848.519

three

850.8

two one hello this is Rob with develop

854.839

andur also known as building better

856.839

developers wanted to announce that we

858.88

have school. developin or.com feel free

861.759

to check it out if you like any of this

864.199

information any of the content that

866.079

we've sent and you would like to see

867.399

more you can come out you can enroll for

869.399

free we have free courses we've got

871.8

places for you to get better at just

874.36

learning a technology or how toos you

876.92

can work on your business skills we can

879.24

help you with becoming a better

880.6

developer as in coding and things like

882.959

that a lot of the stuff you've seen on

884.519

YouTube we also have out at school.

887.279

develop andure we just have it in a

888.88

little more of a educational format and

891.48

a way for you to track your progress as

893.959

you move forward becoming a better

897.68

developer