You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jay Hogan <se...@gmail.com> on 2008/02/14 20:30:31 UTC
AjaxRequestTarget and dynamic form component
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
Re: AjaxRequestTarget and dynamic form component
Posted by Igor Vaynberg <ig...@gmail.com>.
you shouldnt rerender the entire form, just some div that surrounds
the area you are changing
i have something similar going, and there i have a div that is around
the label+editor, so i repaint that diff when i need to swap it out
with a different editor...
-igor
On Thu, Feb 14, 2008 at 12:39 PM, Jay Hogan <se...@gmail.com> wrote:
> Timo,
>
> Thanks for your response. Here's a practical example of how this component
> will be used.
>
> Let's say I have an employee table out in some database that has firstName,
> lastName and department fields. I need to give HR a web page that allows
> them to search for employees based on firstName, lastName and/or department.
> Now I could easily design a page that has a search form with 3 TextField's
> and a submit button to simply get the job done. But what if I have 30 or 40
> tables and all of those tables require search pages....I don't want to
> recreate the wheel each time if I can get away with it. So I design a
> component (thanks to wicket) that accepts general search parameters and
> handles the grunt work. Plus, I can make the search panel more powerful by
> allowing the user to select how they want to search (using =, >, <, LIKE, IN
> etc...).
>
> Getting back to the employees example, I want the search form to look
> something like this:
>
> First Name: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
> search criteria entered by user]
> Last Name: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
> search criteria entered by user]
> Department: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
> search criteria entered by user]
> [SearchButton]
>
> Here is where I am stuck. If the user chooses to search by department using
> the "in list" operator, I want to be able to replace, using AJAX, the
> TextField component with a MultipleListChoice component so they can select 1
> or more departments. I don't really need the form to be submitted every time
> the search operator is changed but when I add the form to
> AjaxRequestTarget.addComponent() the form is re-rendered and my changes are
> lost.
>
> Am I making any sense?
>
> Thanks,
> Jay
>
> On Thu, Feb 14, 2008 at 3:12 PM, Timo Rantalaiho <Ti...@ri.fi>
> wrote:
>
>
>
> > On Thu, 14 Feb 2008, Jay Hogan wrote:
> > > 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
> >
> > Wow, that's a complicated search! I hope that you have a lot
> > of data behind it.
> >
> > > 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
> >
> > Hmm, so are you submitting the entire form when any
> > AjaxEditableChoiceLabel is edited? Have you checked that it
> > does submit the form? If not you might be better off by
> > rolling your own component with AjaxFormSubmittingBehavior.
> >
> > > 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.
> >
> > Have you tried adding a feedback panel to see if there are
> > validation errors?
> >
> > I didn't understand very well what was the expected behavior
> > of each input element and the form (a practical example would
> > be handy).
> >
> > Best wishes,
> > Timo
> >
> > --
> > Timo Rantalaiho
> > Reaktor Innovations Oy <URL: http://www.ri.fi/ >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> ============================================
> Computer Science: solving today's problems tomorrow.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AjaxRequestTarget and dynamic form component
Posted by Jay Hogan <se...@gmail.com>.
Timo,
Thanks for your response. Here's a practical example of how this component
will be used.
Let's say I have an employee table out in some database that has firstName,
lastName and department fields. I need to give HR a web page that allows
them to search for employees based on firstName, lastName and/or department.
Now I could easily design a page that has a search form with 3 TextField's
and a submit button to simply get the job done. But what if I have 30 or 40
tables and all of those tables require search pages....I don't want to
recreate the wheel each time if I can get away with it. So I design a
component (thanks to wicket) that accepts general search parameters and
handles the grunt work. Plus, I can make the search panel more powerful by
allowing the user to select how they want to search (using =, >, <, LIKE, IN
etc...).
Getting back to the employees example, I want the search form to look
something like this:
First Name: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
search criteria entered by user]
Last Name: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
search criteria entered by user]
Department: <SearchOperatorDropDown: =, LIKE, IN LIST> [Textfield to hold
search criteria entered by user]
[SearchButton]
Here is where I am stuck. If the user chooses to search by department using
the "in list" operator, I want to be able to replace, using AJAX, the
TextField component with a MultipleListChoice component so they can select 1
or more departments. I don't really need the form to be submitted every time
the search operator is changed but when I add the form to
AjaxRequestTarget.addComponent() the form is re-rendered and my changes are
lost.
Am I making any sense?
Thanks,
Jay
On Thu, Feb 14, 2008 at 3:12 PM, Timo Rantalaiho <Ti...@ri.fi>
wrote:
> On Thu, 14 Feb 2008, Jay Hogan wrote:
> > 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
>
> Wow, that's a complicated search! I hope that you have a lot
> of data behind it.
>
> > 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
>
> Hmm, so are you submitting the entire form when any
> AjaxEditableChoiceLabel is edited? Have you checked that it
> does submit the form? If not you might be better off by
> rolling your own component with AjaxFormSubmittingBehavior.
>
> > 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.
>
> Have you tried adding a feedback panel to see if there are
> validation errors?
>
> I didn't understand very well what was the expected behavior
> of each input element and the form (a practical example would
> be handy).
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy <URL: http://www.ri.fi/ >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
============================================
Computer Science: solving today's problems tomorrow.
Re: AjaxRequestTarget and dynamic form component
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 14 Feb 2008, Jay Hogan wrote:
> 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
Wow, that's a complicated search! I hope that you have a lot
of data behind it.
> 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
Hmm, so are you submitting the entire form when any
AjaxEditableChoiceLabel is edited? Have you checked that it
does submit the form? If not you might be better off by
rolling your own component with AjaxFormSubmittingBehavior.
> 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.
Have you tried adding a feedback panel to see if there are
validation errors?
I didn't understand very well what was the expected behavior
of each input element and the form (a practical example would
be handy).
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org