listarraylistplayframework-2.0ebeanscala-template

Play!2 framework - can't retrieve list from form


I'm trying to POST a bound form that contains a list. This is my scala template code:

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

The list size is three, but everything else is null. I can retrieve the user email. Here are the relevant areas of the controller:

        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);
        }

model:

@ManyToMany
public List<Recipe> recipes;

@OneToOne(mappedBy="menuPlan")
public User user;

and @Id public Long id;

public String url;

@ManyToMany(cascade = CascadeType.ALL, mappedBy = "recipes")
public List<MenuPlan> menuPlans;

public String name;

I've tried switching the mappedBy to each side of the ManyToMany to see if it was to do with the ownership, but that hasn't helped.

As mentioned at the top, any suggestions on why the elements are returning null when it appears that they are being picked up would be greatly appreciated. Any suggestions on what I could test would also be appreciated!


Solution

  • The Recipes in the list didn't need to be called again. I only needed:

    name="recipes[1].id">
    

    Instead of:

    name="recipes[1].recipe.id">
    

    Amazingly simple. Lost 2 hours on that one!