2012-10-19 5 views
0

여기에 재치가 있습니다. 이것은 매우 사소한 것으로 보이지만 작동하지 않습니다. 나는 서버에 Long (tournamentId) 및 객체 목록을 다시 전달하는 jsp 페이지를 가지고있다. 양식을 게시하면 목록이 제대로 전달되지만 Long 구성원은 전송 된 것으로 볼 수는 있지만 null로 되돌려집니다.컨트롤러에 매개 변수가 전달되지 않음 - 스프링

는 JSP :

<form:form method="post" action="addBets" modelAttribute="gwbCollection"> 
<c:choose> 
<c:when test="${gwbCollection.tournamentState == 'CLOSED_FOR_BETS'}"> 
     <br> 
    </c:when> 
</c:choose> 
<input name="tournamentId" value="${gwbCollection.tournamentId}" type="hidden"/> 
    <table> 
     <tr> 
      <td>Side A:</td> 
      <td>Score A:</td> 
      <td>Side B:</td> 
      <td>Score B:</td> 
     </tr> 
     <c:forEach var="gwb" items="${gwbCollection.games}" varStatus="status"> 
      <tr> 
       <td><input name="games[${status.index}].game.gameId" value="${gwb.game.gameId}" type="hidden"/> 
        <input name="games[${status.index}].userId" value="${gwb.userId}" type="hidden"/> 
        <input name="games[${status.index}].game.tournamentId" value="${gwb.game.tournamentId}" type="hidden"/> 
        <input name="games[${status.index}].bet.betId" value="${gwb.bet.betId}" type="hidden"/> 
        ${gwb.game.sideA}</td> 
       <td><input name="games[${status.index}].bet.scoreA" value="${gwb.bet.scoreA}"/></td> 
       <td>${gwb.game.sideB}</td> 
       <td><input name="games[${status.index}].bet.scoreB" value="${gwb.bet.scoreB}"/></td> 
      </tr> 
     </c:forEach> 
    </table> 
    <c:choose> 
     <c:when test="${gwbCollection.tournamentState == 'OPEN_FOR_BETS'}"> 
      <input type="submit" /> 
     </c:when> 
    </c:choose> 
</form:form> 

감사관 :

@Controller 
@SessionAttributes 
public class BetController { 
... 
@RequestMapping(value = "/addBets", method = RequestMethod.POST) 
public String addBet(@ModelAttribute("gwbCollection") GamesWithBetsCollection gwbCollection) { 
    List<Bet> bets = gwbUtil.getBets(gwbCollection); 
... 
} 

그리고 마지막으로, GamesWithBetsCollection :

public class GamesWithBetsCollection { 
private TournamentState tournamentState; 
private Long tournamentId; 
private List<GameWithBet> games; 

public GamesWithBetsCollection() { 

} 

public List<GameWithBet> getGames() { 
    return games; 
} 

public void setGames(List<GameWithBet> games) { 
    this.games = games; 
} 

public TournamentState getTournamentState() { 
    return tournamentState; 
} 

public void setTournamentState(TournamentState tournamentState) { 
    this.tournamentState = tournamentState; 
} 

public Long getTournamentId() { 
    return tournamentId; 
} 

public void setTournamentId(long tournamentId) { 
    this.tournamentId = tournamentId; 
} 

}

+0

나는 차이를 만들 것이라고 생각하지 않았지만,'tournamentId'가'long'을 기대하지만, 필드와 getter가'Long'을 지정했다는 것을 알았습니다. – nickdos

답변

0

Nickdos - WOW! 그 대답입니다! 아름다운 캐치!

요약하면 "tournamentId"필드는 Long (개체)으로 정의되지만 setter는 매개 변수로 long (프리미티브)을가집니다. Long (오브젝트)로 변경하면 트릭을 만들었습니다.

다시 한번 감사드립니다. Nickdos!

관련 문제