根据这篇文章,我已经实现了基于toString conversion-error-setting-value-com-example-warehousecafebabe-for-null-conver的通用转换器,但是我得到事务中止异常fk_game_id不能为null。我需要做些什么才能让它发挥作用?
JSF:
@Override
public String toString() {
return "entities.Game[ gameId=" + gameId + " ]";
}
游戏实体类中的Generic Converter:
@PostConstruct
public void init() {
this.gameLists = gameFacade.findAll();
this.playerLists = playerFacade.findAll();
this.game = new Game();
this.player = new Player();
this.game.setGameId(Integer.SIZE);
this.player.setPlayerId(Integer.SIZE);
this.playerGame.setFkGameId(game);
this.playerGame.setFkPlayerId(player);
}
public String addPlayerGame() {
this.playerGame = new PlayerGame();
this.playerGameFacade.create(this.playerGame);
return "index";
}
控制器bean:
/
答案 0 :(得分:1)
您可能需要检查gameId和playerId是否在addPlayerGame方法中在控制器中正确填充。对于playerId和gameId将填充在Player&你的控制器的游戏对象,不应该是h:selectOneMenus如下所示:
<h:selectOneMenu id="fkGameId" value="#{controller.game.gameId}"
和
<h:selectOneMenu id="fkPlayerId" value="#{controller.player.playerId}"
我注意到的其他事情是,在addPlayerGame()方法中,您使用new PlayerGame()
重置playerGame对象并将其传递给PlayerGameFacade。相反,您应该按原样传递实例变量playerGame
,因为它包含我们需要保留的用户选择游戏和玩家ID。
public String addPlayerGame() {
this.playerGameFacade.create(this.playerGame);
return "index";
}
如果需要,发布PlayerGameFacade类将有助于进一步调试。