リストを含むバインドされたフォームを POST しようとしています。これは私のscalaテンプレートコードです:
<input type="hidden" value="@recipe.name" name="recipes[0].recipe.name">
<input type="hidden" value="@recipe.id" name="recipes[1].recipe.id">
<input type="hidden" value="@recipe.url" name="recipes[2].recipe.url">
<input type="hidden" value="@user" name="user.email">
</fieldset>
<input type="submit" value="submit" class="btn btn-primary">} </td>
リストのサイズは 3 ですが、それ以外はすべて null です。ユーザーのメールを取得できます。コントローラの関連領域は次のとおりです。
MenuPlan menuPlan = boundForm.get();
User user = User.getUser(menuPlan.user.email);
List<Recipe> recipesForm = menuPlan.recipes;
Logger.info("");
Logger.info("Number of recipes in menuPlan.recipes = " + menuPlan.recipes.size());
Logger.info("Name of recipe = " + menuPlan.recipes.get(1).name);
Logger.info("");
for(Recipe recipe : menuPlan.recipes){
Logger.info("");
Logger.info("The recipe id = " + recipe.id);
Logger.info("");
Logger.info("The recipe name = " + recipe.name);
Logger.info("");
Logger.info("The recipe url = " + recipe.url);
Logger.info("");
//Recipe recipeLoop = Recipe.findById(recipe.name);
//menuPlan.recipes.add(recipeLoop);
}
モデル:
@ManyToMany
public List<Recipe> recipes;
@OneToOne(mappedBy="menuPlan")
public User user;
および @Id public Long id;
public String url;
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "recipes")
public List<MenuPlan> menuPlans;
public String name;
所有権と関係があるかどうかを確認するために、mappedBy を ManyToMany の両側に切り替えてみましたが、それは役に立ちませんでした。
冒頭で述べたように、要素がピックアップされているように見えるのになぜ要素が null を返すのかについての提案は大歓迎です。私がテストできるものについての提案もいただければ幸いです。