Hello Together
following situation / problem:
I have a form to create a game. A game (Business Object) consists of 2 teams (Team is also a BusinessObject), a matchday and a date. The JPS form looks like this:
In the controller to setup the form i get the teamList with the following statements:Code:<form:form modelAttribute="game"> <table> <tr> <td><fmt:message key="game.management.form.game.name.team1" /></td> <td><form:select path="team1" items="${teamList}" itemLabel="name" itemValue="id" /></td> <td><form:errors path="team1" /></td> </tr> <tr> <td><fmt:message key="game.management.form.game.name.team2" /></td> <td><form:select path="team2" items="${teamList}" itemLabel="name" itemValue="id" /></td> <td><form:errors path="team2" /></td> </tr> <tr> <td><fmt:message key="game.management.form.game.startdate" /></td> <td><form:input path="start_date"/></td> <td><form:errors path="start_date" /></td> </tr> <tr> <td><fmt:message key="game.management.form.game.matchday" /></td> <td><form:input path="matchday"/></td> <td><form:errors path="matchday" /></td> </tr>
The business object Game looks like this:Code:@RequestMapping(method = RequestMethod.GET) public String setupForm(ModelMap model) { Game game = new Game(); List<Team> team = teamManager.getAllTeams(); model.addAttribute(game); model.addAttribute(team); return "gameForm"; }
So ... i get a problem when i want to save the new Game. There is no really error or exception. MVC Spring catch the error and show "Invalid data.".Code:public class Game extends BaseEntity { @ManyToOne(fetch=FetchType.EAGER) private Competition competition; @ManyToOne(fetch=FetchType.EAGER) private Team team1; @ManyToOne(fetch=FetchType.EAGER) private Team team2; private int matchday; private Date start_date; // get- and set Method for all this attributes ... ... public abstract class BaseEntity { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id;
Yes, its correct because i have set- and get-Methods to save a Team and not a ID (Integer value). But how can i solve my problem? How can i map between the id and the whole Team Business Object in my Game Business Object?
I hope i could explain where is my problem. :-) If not .. please ask what is unclear.
Thank you for your help and support in advance.
Best regards,
Oliver


Reply With Quote