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. We are working on a complex form for entering data. We our working on form entry and digging through setting up a drop down list with a map as a source and then looking at some string-Double issues.
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 going through our little app conversion here using spring Boot and time leaf and this time around we are going to look at a specific little thing we ran in before we were building options out using this list actually it's a it's a map uh if you go back to the status list you will see somewhere in here where I've got the hello controller we can see that we've got this status list and actually we can see right here it's a it's a map of a string and a string and so what we actually want to do when we get into displaying our dropdowns instead of just having the same thing as a value as we have for the text we actually want it to be the key and the value now there's a couple ways we can do this and in this case uh what I'm going to do is I'm going to do um and I'm just pasting this in because for each of these options instead what we're going to do is we can actually Within just as we did in some others we do some fours we're going to come in here and we're going to do for each entry in the uh what do we call that status list then here what we want to do uh let me just get rid of that so in each of these it's sort of like what we got here we've got an option we've got an each we've got an entry and a status list oops which I don't oh I'm sorry I already had all that my mistake uh what we're going to do is here we're going to just do uh we want the key is going to be I believe the ID that we want and then the value and those are not yeah those are not functions because what we need is when we save we're actually saving the key not the value and this is where I'll show you this in a second uh this is where we're displaying statuses which have like a single letter you like for new it's got an n capital N but the label is actually new so if we run this let's see if this actually gives us what we need wh if we go here and we go log in and we pick a site and we go here so see now before you may have seen that this is a little bit different uh we had the value and if we look at the actual I don't know if it's going to be big enough for you to see but if we look [Music] here if we look down here we will see oh here we go see ID is same so we need to fix that because we have the oh no here we go I'm sorry so here if you can see our option value is p even though we're displaying pending which is very important because then when we go back and save this it's going to grab that value so if we go in and let's just try to save this thing let's just pick some values and make sure we've got it uh let's change a couple uh that works let's just do a save and update see if it works it does not and that's really our goal is we've been wanting to save this so let's see what it complains about this time it may be one of our other lists if we go in here it is complaining about uh cannot add or update a child row references user so we probably don't have the user ID coming in right so what we want to do is go take a look at uh here when we do our save or update uh which is somewhere here here we go here's our saver update and our user ID is going to get the project user ID so we probably are not actually loading that in uh so let's go to our let's see do we have a user ID here uh we do uh but that's set there so get on by so what we probably want to do oh there should be a user ID in here somewhere so if we look are we getting that set right so we have that and it should be user ID if we go look in the hidden right around the form itself self let's see if that's actually coming across form hidden user ID we're not seeing that wait that's interesting because uh form hidden path equals so that's probably what we oh we don't want that we probably want this to be instead like we did with these is it's just going to be a straight up th input or input and uh this is going to be type equals I think we can do hidden we're going to find out in a second if we do that and then this one is going to be input hidden up type equals and then we need the th field here it's going to be ID and user ID so let's see if we get those in so there's a couple of those values that we missed the first time around I think this is all lowercase user ID th field [Music] equals that should hopefully work did I miss a oh there we go I missed a quote so let's try that and let's see what we got here so now if we run that and now if we reset when it comes up uh well let's go ahead and leave that up because we want to go check to see our values are coming through so if we come here and we pick an ID and we pick a form uh let's see form action action where' it go there no that's the div action action where is it there it is so get into our container wrong one get into this one field set form and here we see we've got our csrf we have there we go so now we see that we've got our ID Valu is being set in our user ID values being set so that should let's go change a couple values and this is one called create website let's just we're going to change this name to this one so we're sure we can take a look at it here in a minute and let's see if we do a save uh oh interesting so we did something with home so uh it's probably in the hello where' it go uh if we do the save let's see uh that's start page this this is the projects filter here we go homepage save project here we go so they're doing redirect to home let's see what happens because this one we're going to come through what we want to do is we end up wanting to redirect and I think it's because I had to slash slash that's probably going to be my problem um we're going to find out in a minute this is something else we have not done uh that we have not gone through this uh um a redirect so let's take a look at that or at least I don't think we have let's go take a look at that guy and now I'm pretty sure what we got is it will have already saved so if we go here let's go back one and it'll make us log in oh no it won't um so let's go to Project log in this one see so it did save our values oops and we're seeing something as a problem so now it's got an issue which is uh the operator multiply is not so we got something we missed here oh so we have got something in our types that is causing an issue so uh multiply is not sport to null and a double so something is a null here so what we need to do is we need to go to uh let's see what we probably want to do is figure out which it is so if we go look to our multiply wh then we're going to see here uh let's see and it is in which one it is in oh because we can see which one that was coming from that was coming from here project cost minus project cost so if we go to wherever the project cost thing is let's just go look it up uh Capital C there it is so this thing it doesn't like that we have a null in there somewhere so it's probably the agent percent I'm going to assume uh yes so what we need to do is make sure that our agent percent defaults to zero uh let's see so when we do let's see how do we want to fix that we probably want to fix it let's fix it in the row mapper so what we can do is we can come in here where is row [Music] mappers so we're going to go into our Row mapper for our project and here where it does agent percent see that's a double and it could be project cost so project cost where did we get project C oh maybe project cost because that's a double Su Shi be okay so if we go to hello where is hello let's go look for project cost here there it is so it has a Calculate cost cost oh so one of them's a null Let's do let's [Music] see how we want to do this so let's see did it do it maybe it was in it was calculating it it does not let's go see where we like blew it up oh we probably didn't so let's just do it like this let's do okay well let's look at this Calculate cost so we're going to fix this in a couple places maybe so Calculate cost says select that oh see and this is probably it so if I do this and I do a I bet you if I do it with the project ID if I go here let me just pick one uh let's just do this let's just do a new one and we're going to do it here and it's going to be in uh proposals and let's see project ID equals like 38 I don't care what it is let's just pick one there we go so uh what was the project we can probably find that out 28 so it's still a null and probably if we do uh select star from oh because there's no tasks where project ID equals 28 so we didn't have any task so it's a null um oh typo wh got a typo there we go so what we want to do here is we're just going to say actually um let's just do if null that then it's going to be 0.0 there we go and so we can take that and we're going to jump back over here and we're going to I think that works project okay so now if we run it let's see if we got them working and let's just just rerun it so we've hit a couple of our snags here let's see if we got oh we got another one which is probably going to be another one of our multiply again and it's going to be based on is it the same one hopefully not it is okay so project cost so that means project so we also want to see agent percent which is going to be hello controller uh so we need to do agent percent on the R mapper so let's go back to our project R mapper and agent percent uh here let's do if project project dot get agent percent equals null then we're just going to set the percent equal to 0.0 and now let's see what we got oh there we go so let's see if it runs through now hopefully it does and we will be able to continue on with our stuff oh we're still not getting one and we still have a multiply issue and we have it in oh we still have it here which is interesting so project cost what is the multiply complaining about not be oh string and double so somebody's giving me a double uh so agent percent and the other one should be project cost should be a double as well so if I do get agent percent if I look here on my project uh I want to do it on my project model which is where my models go model model model model there's my module models if I go [Music] here oh get agent percent is also a double so we've got something here that it doesn't like so we probably have a wrong mapping and if we do that okay is that minus that let's do it this way project cost minus project 18% should be that whole thing so let's try that one more time let's see if we got something weird about that and we'll probably have to dive into this next episode because I don't want this oh there we go and it is still probably complaining multiply not supported between string and double am I in the right place and it is still that one okay who project cost project cost here here now we know that so let's do project cost let's just do that first and see if that's the one that we've got we just sort of debug this sucker real quick and in so doing we come in here okay so it doesn't like project cost maybe no it's probably complain about something else now it is complaining about yeah so it's the agent percent most likely is it so if we go back to project. agent percent it is a double so let's just make that 0.0 and um this one is going to be 0.0 and let's see if that works and now if we run it and then we're going to have to come back and fix that and we will tackle that next episode if this works nope where else did we miss it multiply again and oh it doesn't like that see oh um so it is probably something here so we're going to go string and double so we do have something here that we've got to work out is that it is not liking how we have that uh set up essentially so we will tackle that next step episode we're going to go make sure we get our uh our types to comply that being said if you have any questions shoot us an in uh email at info develop or.com and uh thanks for hanging out with us we'll see you again next time go out there and have yourself a great day a great week and we will talk to you next [Music] time
Transcript Segments
[Music]
well hello and welcome back we are
continuing going through our little app
conversion here using spring Boot and
time leaf and this time around we are
going to look at a specific little thing
we ran in before we were building
options out using this
list actually it's a it's a map uh if
you go back to the status list you will
see somewhere in here where I've got the
hello controller we can see that we've
got this status list and actually we can
see right here it's a it's a map of a
string and a string and so what we
actually want to do when we get into
displaying our dropdowns instead of just
having the same thing as a value as we
have for the text we actually want it to
be the key and the value now there's a
couple ways we can do
this and in this case uh what I'm going
to do
is I'm going to do um and I'm just
pasting this in because for each of
these options instead what we're going
to do is we can actually Within just as
we did in some others we do some fours
we're going to come in here and we're
going to do for each entry
in the uh what do we call that status
list then here what we want to do uh let
me just get rid of that so in each of
these it's sort of like what we got
here we've got an option we've got an
each we've got an entry and a status
list oops which I don't oh I'm sorry I
already had all that my mistake
uh what we're going to
do is here we're going to just do uh we
want the key is going to be I believe
the ID that we want and then the value
and those are not yeah those are not
functions because what we need is when
we save we're actually saving the key
not the value and this is where I'll
show you this in a second uh this is
where we're displaying statuses which
have like a single letter you like for
new it's got an n capital N but the
label is actually new so if we run this
let's see if this actually gives us what
we
need wh if we go here and we
go log
in and we pick a site and we go here so
see now before you may have seen that
this is a little bit different uh we had
the value and if we look at the actual I
don't know if it's going to be big
enough for you to see but if we look
[Music]
here if we look down here we will see oh
here we go see ID is same so we need to
fix that because we have the oh no here
we go I'm sorry so here if you can see
our option value is p even though we're
displaying pending which is very
important because then when we go back
and save this it's going to grab that
value so if we go in and let's just try
to save this thing let's just pick some
values and make sure we've got it uh
let's change a
couple uh that works let's just do a
save and update see if it works it does
not and that's really our goal is we've
been wanting to save this so let's see
what it complains about this time it may
be one of our other
lists if we go in
here it is complaining about uh cannot
add or update a child row
references user so we probably don't
have the user ID coming in right so what
we want to do is go take a look
at uh here when we do our save or
update uh which is somewhere here here
we go here's our saver
update and our user ID is going to get
the project user ID so we probably are
not actually loading that in uh so let's
go to
our let's see do we have a user ID here
uh we
do uh but that's set there so get on by
so what we probably want to do oh there
should be a user ID in here
somewhere so if we look are we getting
that set
right so we have that and it should be
user ID if we go look in the hidden
right around the form itself
self let's see if that's actually coming
across form hidden user
ID we're not seeing that wait that's
interesting
because uh form hidden path equals so
that's probably what we oh we don't want
that we probably want this to
be instead like we did with these is
it's just going to be a straight
up th input or
input and uh this is going to
be
type equals I think we can do
hidden we're going to find out in a
second if we do that and then this one
is going to
be input hidden up type
equals
and then we need the th
field
here it's going to be ID and user ID so
let's see if we get those in so there's
a couple of those values that we missed
the first time around I think this is
all lowercase user ID th field
[Music]
equals that should hopefully work did I
miss a oh there we go I missed a quote
so let's try that
and let's see what we got here so now if
we run
that and now if we reset when it comes
up uh well let's go ahead and leave that
up because we want to go check to see
our values are coming through so if we
come here and we pick an ID and we pick
a
form uh let's see form action action
where' it go there no that's the div
action action where is it there it is so
get into our container
wrong one get into this
one field
set
form and here we see we've got our csrf
we have there we go so now we see that
we've got our ID Valu is being set in
our user ID values being set so that
should let's go change a couple
values and this is one called create
website let's just we're going to change
this name to this one so we're sure we
can take a look at it here in a
minute and let's see if we do a
save
uh oh interesting so we did something
with home so uh it's probably in
the hello where' it go uh if we do the
save let's
see uh that's start
page this this is the projects filter
here we go
homepage save project here we go so
they're doing redirect to
home let's see what happens because this
one we're going to come through what we
want to do is we end up wanting to
redirect and I think it's because I had
to slash slash that's probably going to
be my
problem um we're going to find out in a
minute this is something else we have
not done uh that we have not gone
through
this uh um a redirect so let's take a
look at that or at least I don't think
we
have let's go take a look at that guy
and now I'm pretty sure what we got is
it will have already saved so if we go
here let's go back one and it'll make us
log in oh no it
won't um so let's go to
Project log
in this one see so it did save our
values oops and we're seeing something
as a problem so now it's got an issue
which
is uh the operator multiply is not so we
got something we missed here
oh so we have got something in our types
that is causing an issue so uh multiply
is not sport to null and a double so
something is a null here so what we need
to do is we need to go
to uh let's see what we probably want to
do is figure
out which it is so if we go look to our
multiply
wh then we're going to see
here uh let's see and it is in which one
it is in oh because we can see which one
that was coming from that was coming
from
here project cost minus project cost so
if we go to wherever the project cost
thing
is let's just go look it
up uh Capital
C there it is so this thing it doesn't
like that we have a null in there
somewhere so it's probably the agent
percent I'm going to assume
uh yes
so what we need to do is make sure that
our agent percent defaults to
zero uh let's see so when we
do let's see how do we want to fix that
we probably want to fix it let's fix it
in the row
mapper so what we can do is we can come
in here where is row
[Music]
mappers so we're going to go into our
Row mapper for our
project and here where it does agent
percent see that's a double and it could
be project cost so project
cost where did we get project C oh maybe
project cost because that's a double Su
Shi be okay so if we go to hello where
is
hello let's go look for
project cost here there it is so it has
a Calculate cost
cost oh so one of them's a
null Let's
do let's
[Music]
see how we want to do this so let's see
did it do it maybe it was in it was
calculating it it does not let's go see
where we like blew it
up oh we probably didn't so let's just
do it like this let's do
okay well let's look at this Calculate
cost so we're going to fix this in a
couple places maybe so Calculate
cost says select
that oh see and this is probably it so
if I
do this and I do
a I bet you if I do it with the project
ID if I go here let me just pick
one uh let's just do
this let's just do a new one and we're
going to do it here and it's going to be
in uh proposals and let's see project ID
equals like 38 I don't care what it is
let's just pick
one there we go
so uh what was the project we can
probably find that
out
28 so it's still a null and probably if
we do uh select star from oh because
there's no
tasks
where project ID equals 28 so we didn't
have any task so it's a null um oh typo
wh got a
typo there we go so what we want to do
here is we're just going to say actually
um let's just do
if null
that then it's going to be
0.0 there we go and so we can take that
and we're going to jump back over here
and we're going to I think that
works project okay so now if we run it
let's see if we got them
working and let's just just rerun
it so we've hit a couple of our snags
here let's see if we got oh we got
another
one which is probably going to be
another one of
our
multiply again and it's going to be
based on is it the same one hopefully
not it is okay so project cost so that
means project so we also want to see
agent percent
which is going to
be hello
controller uh so we need to do agent
percent on the R
mapper so let's go back to our project R
mapper and agent
percent uh here let's do
if
project project dot get
agent percent equals
null then we're just going to set the
percent equal
to
0.0 and now let's see what we got
oh there we go so let's see if it runs
through now hopefully it
does
and we will be able to continue on with
our stuff oh we're still not getting
one and we still have a multiply issue
and we have it in oh we still have it
here which is interesting so project
cost what is the multiply complaining
about not be oh string and double so
somebody's giving me a
double uh so agent
percent and the other one should
be project cost should be a double as
well so if I do get agent percent if I
look here on my
project uh I want to do it on my project
model which is where my models go model
model model model there's my module
models if I go
[Music]
here oh get agent percent is also a
double so we've got something here that
it doesn't
like so we probably have a wrong
mapping and if we do
that okay is that minus that
let's do it this
way project cost minus project
18% should
be that whole
thing so let's try that one more
time
let's see if we got something weird
about
that and we'll probably have to dive
into this next
episode because I don't want this oh
there we
go and it is still probably complaining
multiply not supported between string
and
double am I in the right
place and it is still that one okay who
project cost project cost here
here now we know that so let's do
project
cost let's just do that
first and see if that's the one that
we've
got we just sort of debug this sucker
real quick and in so
doing we come in here okay so it doesn't
like project cost maybe no it's probably
complain about something else now it is
complaining
about
yeah so it's the agent percent most
likely is
it so if we go back to project. agent
percent it is a
double so let's just make
that
0.0 and um this one is going to be
0.0 and let's see if that
works and now if we run it and then
we're going to have to come back and fix
that and we will tackle that next
episode if this works nope where else
did we miss
it multiply again
and oh it doesn't like that see oh um so
it is probably something
here so we're going to go string and
double so we do have something here that
we've got to work out is that it is not
liking how we have
that uh set up essentially
so we will tackle that next step episode
we're going to go make sure we get our
uh our types to comply that being said
if you have any questions shoot us an in
uh email at info develop
or.com and uh thanks for hanging out
with us we'll see you again next time go
out there and have yourself a great day
a great week and we will talk to you
next
[Music]
time