I'm not sure if I've even labelled this question properly. But what I'm trying to do is map a Javabean to form inputs that I have. Except the Bean contains a complex type property that I want to map to (well I want to map to a property of it to be specific). Let me explain with code. I have a game class:
public class Game
{
private GameStatistics gameStats;
public GameStatistics getGameStats() {
if(gameStats == null){
gameStats = new GameStatistics();
}
return gameStats;
}
public void setGameStats(GameStatistics value) {
gameStats = value;
}
}
and I have a GameStatistics class:
private int amountOfNumbersToMemorise;
public int getAmountOfNumbersToMemorise() {
return amountOfNumbersToMemorise;
}
public void setAmountOfNumbersToMemorise(String value) {
amountOfNumbersToMemorise = Integer.parseInt(value);
}
then in my JSP I have something like:
<jsp:useBean id='game' scope='session' class='Classes.Game' />
<form method="Post" action="numberDisplay.jsp">
Enter your username: <input name="username" type="text" /> <br />
How many numbers to remember: <input name="gameStats.amountOfNumbersToMemorise" type="text"/> <br />
<input type="Submit" value="Show me the numbers!" />
</form>
the above page goes to another page:
<jsp:useBean id='game' scope='session' class='Classes.Game' />
<jsp:setProperty name="game" property="*"/>
//more code here
<ul>
<% for(int x=0; x < game.getNumbersToMemorise().size(); x++)
{%>
<li><%=game.getNumbersToMemorise().get(x) %> </li>
<% } %></ul>
// more code
There are some properties I haven't included because they aren't important but I can't seem to map the numbers entered into the second input box to a property on the complex type.
I can't use MVC as this is an assignment and we have to do it this way :(
Does this make sense? I'm pretty new to Java (I'm a C# person) so any help would be greatly appreciated, thanks :)