I think your issue is with the way you set it up.
It looks to me as if your DropDownChoice is isolated from your data model so that when the form submits you getting the property set to null, which it is in the input.

could of things to try:
- use a property model for the form model.
- name the dropdown after the field in the data object you actually want to populate from input (category in this case)

- Brill


On 28-Feb-09, at 11:17 AM, Azzeddine Daddah 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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to