Hi,
I'm trying to use a DropDownChoice to display and store the selected
category in the database. The value selected in the drop down is correctly
set, but when I look to the model (Category) of this drop down, it returns
always null. Do I do something wrong? Below some code.

public AddRecipeForm(String id) {
        super(id);
        setModel(new Model<Recipe>(new Recipe()));
        ...
        add(new CategoriesDropDown("categories",
recipe.getCategory()).setRequired(true));
}
...
public void onSubmit() {
    RecipeService recipeService = RecipeService.getInstance();
    Recipe recipe = form.getModelObject();
    Category cat = recipe.getCategory(); // This returns always null
}

...

private class CategoriesDropDown extends DropDownChoice<Category> {
        public CategoriesDropDown(String id, Category category) {
            super(id, new Model<Category>(category),
RecipeService.getInstance().getAllPersistentRecipeCategories(), new
IChoiceRenderer<Category>() {
                @Override
                public String getIdValue(Category category, int index) {
                    return category.getName();
                }

                @Override
                public Object getDisplayValue(Category category) {
                    return category.getName();
                }
            });
        }
    }


Kind regards,

Hbiloo

Reply via email to