So let's take a look at the code at this new method, greetByPeriod to
application. So, here I'm in Hello world
and poin.java, I've defined my new function greetByPeriod.
Still got the name argument, and it's
got a named period argument, period. And just
for variety, although the name is @Named
period. I'm calling the argument time of day,
just to show that whatever the @Named is what is required to be specified
in the request. And I'm all doing here is returning new HelloClass name, time of
day. HelloClass class, didn't actually have this
constructor, so I added it, it's pretty
simple. Here's the new construction HelloClass. Pass
the name, the period, construct a new message,
good, this would be morning, let's say, good morning
Lauren. Good morning Lauren. Okay, so let's see if it
works. I'm going to run it on the dev
server, save my changes, it's always a good thing to
do. Mkay, let's go over to the local host
in the browser. And I'm going to go straight to
the API's explorer. Oh goodness, got an error, that
never happens. Failed to retrieve API configs with status: 500.
All right, first instinct panic, second instinct go
back and check the code. And you see I
got the error showing up here too, Failed
to retrieve API configs. That means there is something
wrong with my end point function. Let's look
at hello world end points greetByPeriod all looks good,
what's the problem? Aha, it's a copy and
paste error. See here, I copy and pasted this
from the previous method sayHelloByName. And I
forgot to update the function name. So I'll
just fix that real quick. You can't have
two functions exposed with the same name. Actually
greet by period. Save it. And actually when you make changes in the Java code
and you save it. You'll usually find that
the changes get automatically propagated out to localhost.
See it says, reloading the web application, a
file has changed. So I don't need to
run it again. I'll just go straight to
local host, reload the APIs Explorer. Okay good.
This time it worked. Now drill down into my API. Here's my new one, greet by
period. Enter a name. And it's the afternoon
now. And then let's look at the response.
There it is. Good afternoon. And then Good afternoon Buttercup, because
Buttercup's the name I gave. So one other thing to look at is the code for
index.html and hello.js. Take a quick look
at those, index.html. Really what we had to do was add the,
the new imput field for period is called Period_Field and
the new button for the greeting and in Hello.js.
And enable buttons that we needed to enable to
function for the new button. Here's the new button,
input greetByPeriod. We're going to call the function greetByPeriod. We're going
to update the button label. Now we have to
define greet by period and here it is, it's
very similar to greet by name. But we get
the name field, we get the value of the name
out of the HTML, we get the period
out of the period field element. You construct
the request. And here we're calling the greetByPeriod
function. And then we're specifying the argument. The
arguments are name and period. Now because we've
called the period, we've named the period argument,
at period. This must exactly match. And then
we execute it and we call the sayHelloCallBack
as before. And again, it throws up an alert dialog box showing
us the message in the response. So, that's all there is to it.