where is the code that creates your form? and is Recipe serializable? -igor
On Sat, Feb 28, 2009 at 8:58 AM, Azzeddine Daddah <[email protected]> wrote: > Thanks Igor, > I've already tried that but still have the same problem. > add(new CategoriesDropDown("categories", new PropertyModel<Category>(recipe, > "category")).setRequired(true)); > ... > private class CategoriesDropDown extends DropDownChoice<Category> { > public CategoriesDropDown(String id, IModel<Category> model) { > super(id, model, > 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(); > } > }); > } > } > > > > On Sat, Feb 28, 2009 at 5:54 PM, Igor Vaynberg <[email protected]>wrote: > >> 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] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
