RE: Updating form fields on dropdown selection change

2013-08-16 Thread Lucio Crusca
No replies... that must mean something... let's try rewording.

I need to build several forms with:

1. Several text fields each, bound to several String properties of a
single bean through a CompoundPropertyModel. This is a requirement unless
it renders all the rest impossible to implement.

2. One DropDownChoice each, bound to a field of the same bean, likely
through a PropertyModel, but this model type is not a requirement.

3. The DropDownChoice must update some of the text fields when the user
selects an item while keeping input in other text fields intact.

Is that possible at all with wicket? If yes, how?

I've already tried adding an AjaxFormComponentUpdatingBehavior(onchange)
to the DropDownChoice and, meanwhile, updating the bean String properties
in the onSelectionChanged method, but doing so the text fields do not get
updated in the form (or the update is reverted so fast I can't see it
actually happened). The onSelectionChanged method is being called after
the onUpdate method.



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



Re: Updating form fields on dropdown selection change

2013-08-16 Thread Martin Grigorov
Hi,


On Fri, Aug 16, 2013 at 10:58 AM, Lucio Crusca lu...@sulweb.org wrote:

 No replies... that must mean something... let's try rewording.

 I need to build several forms with:

 1. Several text fields each, bound to several String properties of a
 single bean through a CompoundPropertyModel. This is a requirement unless
 it renders all the rest impossible to implement.

 2. One DropDownChoice each, bound to a field of the same bean, likely
 through a PropertyModel, but this model type is not a requirement.

 3. The DropDownChoice must update some of the text fields when the user
 selects an item while keeping input in other text fields intact.

 Is that possible at all with wicket? If yes, how?


Everything is possible.
Just different tasks take different time to implement.
What did you try and what issues you faced so far ?



 I've already tried adding an AjaxFormComponentUpdatingBehavior(onchange)
 to the DropDownChoice and, meanwhile, updating the bean String properties
 in the onSelectionChanged method, but doing so the text fields do not get


onSelectionChanged() is non-Ajax update. Using
AjaxFormComponentUpdatingBehavior(onchange) is Ajax update.


 updated in the form (or the update is reverted so fast I can't see it
 actually happened). The onSelectionChanged method is being called after
 the onUpdate method.



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




Re: Updating form fields on dropdown selection change

2013-08-16 Thread Lucio Crusca
 Everything is possible.
 Just different tasks take different time to implement.
 What did you try and what issues you faced so far ?

Please see my previous message. To recap, I tried a mix you just told me
it can't work: I added the TextFields to the AjaxRequestTarget while
updating the bean in the onSelectionChanged method. I didn't know they
could not work together.

 onSelectionChanged() is non-Ajax update. Using
 AjaxFormComponentUpdatingBehavior(onchange) is Ajax update.

Ok, but I need to know the selected item in order to update the String
properties accordingly. AjaxFormComponentUpdatingBehavior(onchange)
doesn't tell me the selected item, while onSelectionChanged seems to be
the wrong way to accomplish what I'm trying to do (see the first post of
Paul Bors in this thread).




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



Re: Updating form fields on dropdown selection change

2013-08-16 Thread Martin Grigorov
On Fri, Aug 16, 2013 at 12:12 PM, Lucio Crusca lu...@sulweb.org wrote:

  Everything is possible.
  Just different tasks take different time to implement.
  What did you try and what issues you faced so far ?

 Please see my previous message. To recap, I tried a mix you just told me
 it can't work: I added the TextFields to the AjaxRequestTarget while
 updating the bean in the onSelectionChanged method. I didn't know they
 could not work together.

  onSelectionChanged() is non-Ajax update. Using
  AjaxFormComponentUpdatingBehavior(onchange) is Ajax update.

 Ok, but I need to know the selected item in order to update the String
 properties accordingly. AjaxFormComponentUpdatingBehavior(onchange)
 doesn't tell me the selected item, while onSelectionChanged seems to be
 the wrong way to accomplish what I'm trying to do (see the first post of
 Paul Bors in this thread).


AjaxFormComponentUpdatingBehavior updates the DropDownChoice's model.
You can use it to read the newly selected value.

Don't use onSelectionChanged() at all if you want to use Ajax.






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




RE: Updating form fields on dropdown selection change

2013-08-15 Thread Lucio Crusca
 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.

I've tried to follow that example and implement something similar in my
code, however I had hard time in making it work (I didn't manage to) and I
found there are two differences between sample code and my code that make
me suspect it can't apply to my case. First, I use CompundPropertyModels
instead of AbstractReadonlyModels, and they are so handy that it would be
a real pity having to write models myself, but I hope that's doesn't make
a real difference.
Second I have a CompoundPropertyModel that manages the whole bean: the
bean fields match the form fields, and one of those fields is the
@ManyToOne (DropDownChoice) and it should update (onchange) a few other
fields of the same bean, but not all of them. In the sample code there are
two different models instead, one for each form field.
For the DropDownChoice I create a PropertyModel on demand just for it,
but I don't keep a reference to it. My code is:

DropDownChoiceQ ddc = new DropDownChoice(id, new
PropertyModelQ(instanceOfTheMany, manyToOneFieldName), elementsList,
choiceRenderer);

Please note that instanceOfTheMany is my bean with the @ManyToOne field
and that the same bean is being managed by the CompoundPropertyModel in
the form.

Now changing that logic in my case is possible but quite troublesome, so
I'd go down that path only if you tell me my current code is broken and
it's the cause of my problems. Just in case you tell me that, if you could
add some hint about how to make it correct it would be very appreciated.


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



Updating form fields on dropdown selection change

2013-08-14 Thread Lucio Crusca
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Updating form fields on dropdown selection change

2013-08-14 Thread Paul Bors
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:lu...@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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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



RE: Updating form fields on dropdown selection change

2013-08-14 Thread Lucio Crusca
 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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Updating form fields on dropdown selection change

2013-08-14 Thread Paul Bors
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:lu...@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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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



RE: Updating form fields on dropdown selection change

2013-08-14 Thread Lucio Crusca
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Updating form fields on dropdown selection change

2013-08-14 Thread Lucio Crusca
 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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org