You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Lucio Crusca <lu...@sulweb.org> on 2013/08/14 14:52:29 UTC

Updating form fields on dropdown selection change

I have a DropDownChoice that should update some form fields when the user
selects an item. My selection-changed-listener code is along the lines of:

 form.modelChanging();

 T obj = model.getObject();
 obj.setFoo(newSelection.getFoo());
 obj.setBar(newSelection.getBar());

 form.modelChanged();
 form.clearInput();
 form.visitChildren();

The problem is that without clearInput() the form fields do not update,
while with clearInput they do update, but I loose any input also in fields
other than FOO and BAR. I need a way to update only FOO and BAR fields and
let other fields alone so that they keep their current user input.

Thanks in advance for your help.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Updating form fields on dropdown selection change

Posted by Lucio Crusca <lu...@sulweb.org>.
> 1. where wicket is made aware of the fact that the target is actually the
> "models" dropdown and not something else in the form?
>
> I'm not sure I understand this question but I think the answer you're
> looking for is: because it has a behavior attached to a component to which
> you can gain access to its model. I would suggest you take a look over
> chapter 16 "Working with AJAX" of the Wicket Free Guide
> (http://wicket.apache.org/learn/books/freeguide.html).

Sorry, it was so obvious that I didn't notice it, I'm not surprised you
aren't sure to understand... the place where wicket is being made aware of
what it should update is just inside the inner class in the only single
method that's being called: target.add(models).




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Updating form fields on dropdown selection change

Posted by Paul Bors <pa...@bors.ws>.
1. where wicket is made aware of the fact that the target is actually the "models" dropdown and not something else in the form?

I'm not sure I understand this question but I think the answer you're looking for is: because it has a behavior attached to a component to which you can gain access to its model. I would suggest you take a look over chapter 16 "Working with AJAX" of the Wicket Free Guide (http://wicket.apache.org/learn/books/freeguide.html).


2. the constructor 'new AjaxFormComponentUpdatingBehavior("onchange")'
does not seem to exist in Wicket 6. Can I just use the no args constructor?

Wicket Library is using Wicket 1.5.10. Take a look over the Migration to 6.0 guide:
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+6.0#MigrationtoWicket6.0-Ajax
You might want to use org.apache.wicket.ajax.form.OnChangeAjaxBehavior or some other subclass of AjaxEventBehavior. 


3. Can I use the AjaxRequestTarget to update a text field also, even if in the example it updates a dropdownchoice?

You can update any component you would like using a AjaxRequestTarget. Just make sure you call setOutputMarkupId(true) on the components you're planning on updating so that it has an ID attribute for JQuery to find it. If you don't, Wicket will remind you via a runtime exception :)

~ Thank you,
  Paul Bors

-----Original Message-----
From: Lucio Crusca [mailto:lucio@sulweb.org] 
Sent: Wednesday, August 14, 2013 2:37 PM
To: users@wicket.apache.org
Subject: RE: Updating form fields on dropdown selection change

> Take a look at how one drop-down updates the other via Ajax in the 
> Wicket Examples at:
> http://www.wicket-library.com/wicket-examples/ajax/choice

Thanks for the suggestion, that code looks good. However I don't understand a number of things:

1. where wicket is made aware of the fact that the target is actually the "models" dropdown and not something else in the form?

2. the constructor 'new AjaxFormComponentUpdatingBehavior("onchange")'
does not seem to exist in Wicket 6. Can I just use the no args constructor?

3. Can I use the AjaxRequestTarget to update a text field also, even if in the example it updates a dropdownchoice?




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Updating form fields on dropdown selection change

Posted by Lucio Crusca <lu...@sulweb.org>.
I wrote:
> 2. the constructor 'new AjaxFormComponentUpdatingBehavior("onchange")'
> does not seem to exist in Wicket 6. Can I just use the no args
> constructor?

Please ignore this one, I was using
AjaxFormChoiceComponentUpdatingBehavior instead by mistake.




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Updating form fields on dropdown selection change

Posted by Lucio Crusca <lu...@sulweb.org>.
> Take a look at how one drop-down updates the other via Ajax in the Wicket
> Examples at:
> http://www.wicket-library.com/wicket-examples/ajax/choice

Thanks for the suggestion, that code looks good. However I don't
understand a number of things:

1. where wicket is made aware of the fact that the target is actually the
"models" dropdown and not something else in the form?

2. the constructor 'new AjaxFormComponentUpdatingBehavior("onchange")'
does not seem to exist in Wicket 6. Can I just use the no args
constructor?

3. Can I use the AjaxRequestTarget to update a text field also, even if in
the example it updates a dropdownchoice?




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Updating form fields on dropdown selection change

Posted by Paul Bors <pa...@bors.ws>.
Take a look at how one drop-down updates the other via Ajax in the Wicket Examples at:
http://www.wicket-library.com/wicket-examples/ajax/choice

I suggest you do something similar instead of trying to re-implement part of the form processing in your code.

Besides, what is going to happen when the next version of Wicket comes along and the form processing changes?
You'll have to re-implement your panels.

~ Thank you,
  Paul Bors

-----Original Message-----
From: Lucio Crusca [mailto:lucio@sulweb.org] 
Sent: Wednesday, August 14, 2013 8:52 AM
To: users@wicket.apache.org
Subject: Updating form fields on dropdown selection change

I have a DropDownChoice that should update some form fields when the user selects an item. My selection-changed-listener code is along the lines of:

 form.modelChanging();

 T obj = model.getObject();
 obj.setFoo(newSelection.getFoo());
 obj.setBar(newSelection.getBar());

 form.modelChanged();
 form.clearInput();
 form.visitChildren();

The problem is that without clearInput() the form fields do not update, while with clearInput they do update, but I loose any input also in fields other than FOO and BAR. I need a way to update only FOO and BAR fields and let other fields alone so that they keep their current user input.

Thanks in advance for your help.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org