use a property model instead of recipe.getcategories() -igor
On Sat, Feb 28, 2009 at 8:17 AM, Azzeddine Daddah <[email protected]> wrote: > 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 > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
