Java Reference
In-Depth Information
F IGURE 33.15
The user enters a guess and the program displays the result.
23
24
public String getResponse() {
get response
25
if (guessString == null )
26
return "" ; // No user input yet
27
28
int guess = Integer.parseInt(guessString);
check guess
29
if (guess < number)
30
return "Too low" ;
31
else if (guess == number)
32
return "You got it" ;
33
else
34
return "Too high" ;
35 }
36 }
The managed bean uses the @ViewScope annotation (line 7) to set up the view scope for the
bean. The view scope is most appropriate for this project. The bean is alive as long as the view
is not changed. The bean is created when the page is displayed for the first time. A random
number between 0 and 99 is assigned to number (line 13) when the bean is created. This
number will not change as long as the bean is alive in the same view.
 
Search WWH ::




Custom Search