Hello wicket-users,

Here's what I'm trying to do. I'm designing a SearchPanel component that
accepts a List<SearchField> and renders these items on a search form. The
SearchField object has properties for search field name, search operator (an
enum), search value and a list of allowed search operators. I am following
the dynamic form
elements<http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html>example
on the wiki which uses a ListView (with itemReuse = true) to render
an abitrary number of elements. This part works great - I have a field
label, a search operator selector (an AjaxEditableChoiceLabel) and search
value widget that can be a TextField, DropDownChoice or DatePicker, etc...,
wrapped in a Panel. In the onSubmit method of the operator component (an
AjaxEditableChoiceLabel), I want to be able to swap out the search value
panel based on the operator the user chose. For instance, if the user
selects "equal to", a TextFieldPanel is added but if the user chooses "in
list", a ListChoicePanel is used.

This is where I run into problems. If I add the form component to the
AjaxRequestTarget provided by AjaxEditableChoiceLabel.onSubmit, any dirty
form components lose their values. I've tried to add a call to
form.processin the
AjaxEditableChoiceLabel.onSubmit method in attempt to force the form to
update it's model, but that doesn't work. I also tried just adding the
ListItem to the AjaxRequestTarget but the component is not re-rendered by
the target.

private Form searchForm;
...
private class SearchItemList extends ListView {
...
@Override
protected void populateItem(final ListItem item) {
    final SearchField field = (SearchField)item.getModelObject();
    item.setOutputMarkupId(true);
    item.add(new Label("label", field.getLabel()));
    item.add(new AjaxEditableChoiceLabel("operator", new
PropertyModel(field,"operator"), field.getAllowedOperators()) {
        private static final long serialVersionUID = 1L;
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            target.addComponent(addOrReplaceValuePanel(item,field));
            target.addComponent(searchForm);
        }
    });
    // addOrReplaceValuePanel is simply a case statement that adds the
appropriate Value panel based on field.getoperator.
    addOrReplaceValuePanel(item,field)
}
}

Any ideas? Am I taking the wrong approach? Am I making a
stupid-wicket-newbie mistake? I'm open to suggestions.

Cheers,
Jay

Reply via email to