Results 1 to 2 of 2

Thread: Mapping ID to BusinessObject

  1. #1
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    15

    Question Mapping ID to BusinessObject

    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:

    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>
    In the controller to setup the form i get the teamList with the following statements:

    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";
        }
    The business object Game looks like this:

    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;
    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.".

    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

  2. #2
    Join Date
    Apr 2007
    Location
    Wellington, New Zealand
    Posts
    125

    Default

    Hi Krusty,

    Your form backing object, jsp pages, and controllers look good, all you need to do now is tell Spring how to convert a team id into a team.

    Have a look into property editors and data binding.

    Hope this helps

    Josh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •