I'm trying to pass form text from my XHTML file into my java bean class into a variable called userNumber but cannot work out how to pass the user inputted number into the java bean class variable.
Here is the code for the XHTML file:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Numbers Page</title>
</h:head>
<h:body>
<h1></h1>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>Your guess: <h:form> <input type="text" name="numberGuess">
<p></p>
<h:commandButton value="Play" action="game_result"/>
</input></h:form></p>
</h:body>
</html>
Here is the code for the java bean class:
import java.util.Random;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class GameBean
{
public String getNumber()
{
String userNumber = request.getparameter("numberGuess");
return userNumber;
}
public int getLuckyNumber()
{
Random number = new Random();
return number.nextInt(1000000)+1;
}
}
Please help! Thanks!