Java Reference
In-Depth Information
Click here to view code image
var msg = function msg(data) {
var resultArea = document.getElementById("AjaxGuess:result");
var errorArea = document.getElementById("AjaxGuess:errors1");
if (errorArea.innerHTML !== null && errorArea.innerHTML !== "")
{
resultArea.innerHTML="";
}
};
The msg function obtains a handle to both the result and errors1 elements. If the
errors1 element has any content, the function erases the content of the result ele-
ment, so the stale output does not appear in the page.
The UserNumberBean Managed Bean
A small change is also made in the UserNumberBean code so that the output compon-
ent does not display any message for the default (null) value of the property response .
Here is the modified bean code:
Click here to view code image
public String getResponse() {
if ((userNumber != null) && (userNumber.compareTo(randomInt) ==
0)) {
return "Yay! You got it!";
}
if (userNumber == null) {
return null;
} else {
return "Sorry, " + userNumber + " is incorrect.";
}
}
Running the ajaxguessnumber Example
You can use either NetBeans IDE or Ant to build, package, deploy, and run the
ajaxguessnumber example.
To Build, Package, and Deploy the ajaxguessnumber Example Using NetBeans IDE
This procedure builds the application into the tut-install /examples/web/
ajaxguessnumber/build/web/ directory. The contents of this directory are de-
ployed to the GlassFish Server.
1. From the File menu, choose Open Project.
Search WWH ::




Custom Search