2012-10-19 1 views
0

Je suis à la fin ici. Cela semble une chose très triviale mais ça ne marche pas. J'ai une page jsp qui renvoie au serveur un Long (tournamentId) et une liste d'objets. Lorsque je publie le formulaire, la liste est passée correctement, mais le membre Long revient en tant que null, même si je peux voir qu'il a été envoyé.Paramètre non transmis au contrôleur - Ressort

Le 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> 

Le contrôleur:

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

Et enfin, 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

Je n'aurais pas pensé que cela ferait une différence mais je remarque que votre setter pour 'tournoiId' attend un' long' mais votre champ et getter spécifient un 'Long'. – nickdos

Répondre

0

Nickdos - WOW! C'est la réponse! Belle prise! Pour récapituler - le champ "tournoiId" est défini comme Long (objet), mais le paramètre est long (primitif) comme paramètre. Le changer en Long (objet) a fait l'affaire.

Merci encore Nickdos!

Questions connexes