0% found this document useful (0 votes)
2 views1 page

ajax

Uploaded by

info.gleone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

ajax

Uploaded by

info.gleone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercises: Ajax

1. Make a button that, when pressed, updates the current time (new Date()) that is shown on the
page, but without reloading the page. Note that you don’t need a real action for the button in
this case, since the getter method for the time presumably returns a new value on each invoca-
tion. So, you can do something like this:
<h:commandButton value="Update Time" action="nothing">
<f:ajax render="timeResult"/>
</h:commandButton>
...
<h:outputText value="#{...}" id="timeResult"/>...

Hint: as long as you remember to define the f: namespace, this is an amazingly simple exer-
cise.

2. Make a button that, when pressed, prints out how many times that particular user has pressed
the button. (“You have pressed the button x times.” should be inserted into the page. Update
the count by 1 whenever the button is pressed.) Hint: easy once you combine Ajax with the
appropriate managed bean scope.

3. Make two textfields to gather two numbers. Make a pushbutton that, when pressed, inserts the
sum of the two numbers into the page. Hint: remember the “execute” attribute.

4. Make an Ajaxified version of the a, b, c, victory, defeat application. This time, have a single
page or section that originally has a heading that says “A”. When the user presses the button,
they should have a 50/50 chance of having the heading change to “B” or “Defeat”. If the
heading says “B” and they press the button, they should have a 50/50 chance of “C” or
“Defeat”, and if the heading says “C” and they press the button, they should have a 50/50
chance of “Victory” or “Defeat”. If they press the button on either the Victory or Defeat page,
they should just see the same message (i.e., “Victory” or “Defeat”) they were already seeing.
To simplify testing, also add a “Give Up and Start Over” button that resets to heading A.

5. Make a combobox (dropdown menu) containing “Baltimore”, “Washington DC”, and “Phila-
delphia”. Based on the city selected, you should insert three separate entries in the page:
• The name of the city
• The name of the city’s NFL team
• The name of the city’s MLB team

Customized Java EE training: JSF 2, PrimeFaces, Hadoop, Java 7, Ajax, jQuery, Android, Spring, REST, etc. http://www.coreservlets.com

You might also like