target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread eugenebalt

I have a piece of Ajax code, attached to some field (let's call it
sourceField), which looks like this:


sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
{

 protected void onUpdate(AjaxRequestTarget target) 
 {
   target.addComponent(Field2);
 }
}


As you can see, Field2 is not changed in any way, it is not cleared or
modified (so this code shouldn't really do anything).

However, when this Ajax runs on changing the sourceField, the Field2's
values get erased! Field2 is actually a CheckBoxMultipleChoice, and all the
checkbox selections get erased as soon as I do target.addComponent().

Why does this happen? Any ideas on what's causing this?

(Field2 is a CheckBoxMultipleChoice, initially initialized with some list,
and its outputMarkerId = true, to make it work with Ajax.)

Thanks
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159543.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Igor Vaynberg
im going to guess that the field is repainted with the values the
serverside thinks should be selected. if the values from the
clientside are not processed by the serverside before the ajax update
they will be different, and so the serverside state overrides the
clientside state.

-igor

On Tue, Dec 21, 2010 at 9:50 PM, eugenebalt eugeneb...@yahoo.com wrote:

 I have a piece of Ajax code, attached to some field (let's call it
 sourceField), which looks like this:


 sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
 {

     protected void onUpdate(AjaxRequestTarget target)
     {
           target.addComponent(Field2);
     }
 }


 As you can see, Field2 is not changed in any way, it is not cleared or
 modified (so this code shouldn't really do anything).

 However, when this Ajax runs on changing the sourceField, the Field2's
 values get erased! Field2 is actually a CheckBoxMultipleChoice, and all the
 checkbox selections get erased as soon as I do target.addComponent().

 Why does this happen? Any ideas on what's causing this?

 (Field2 is a CheckBoxMultipleChoice, initially initialized with some list,
 and its outputMarkerId = true, to make it work with Ajax.)

 Thanks
 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159543.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 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: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Jeremy Thomerson
On Tue, Dec 21, 2010 at 1:50 PM, eugenebalt eugeneb...@yahoo.com wrote:


 I have a piece of Ajax code, attached to some field (let's call it
 sourceField), which looks like this:


 sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
 {

 protected void onUpdate(AjaxRequestTarget target)
 {
   target.addComponent(Field2);
 }
 }


 As you can see, Field2 is not changed in any way, it is not cleared or
 modified (so this code shouldn't really do anything).

 However, when this Ajax runs on changing the sourceField, the Field2's
 values get erased! Field2 is actually a CheckBoxMultipleChoice, and all the
 checkbox selections get erased as soon as I do target.addComponent().

 Why does this happen? Any ideas on what's causing this?

 (Field2 is a CheckBoxMultipleChoice, initially initialized with some list,
 and its outputMarkerId = true, to make it work with Ajax.)


Because you're doing this in an AJAX request that is only submitting the
value(s) of sourceField, and not Field2.  Then you repaint Field2, and it
has no values, and gets replaced on the client side.  You need to submit the
whole form or at least both fields.


-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Hielke Hoeve
Did the field2 have an initial value or did you set the value in your
browser and then let the ajax run?

Hielke

On 21 Dec 2010 20:51, eugenebalt eugeneb...@yahoo.com wrote:


 I have a piece of Ajax code, attached to some field (let's call it
 sourceField), which looks like this:


 sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
 {

 protected void onUpdate(AjaxRequestTarget target)
 {
   target.addComponent(Field2);
 }
 }


 As you can see, Field2 is not changed in any way, it is not cleared or
 modified (so this code shouldn't really do anything).

 However, when this Ajax runs on changing the sourceField, the Field2's
 values get erased! Field2 is actually a CheckBoxMultipleChoice, and all
the
 checkbox selections get erased as soon as I do target.addComponent().

 Why does this happen? Any ideas on what's causing this?

 (Field2 is a CheckBoxMultipleChoice, initially initialized with some list,
 and its outputMarkerId = true, to make it work with Ajax.)

 Thanks
 --
 View this message in context:
http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159543.html
 Sent from the Users forum mailing list archive at Nabble.com.

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



Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Jeremy Thomerson
Awesome!  I love the Wicket community.  11 minutes after the initial post,
there are three very helpful answers.  Great work everyone!

On Tue, Dec 21, 2010 at 2:01 PM, Hielke Hoeve hielke.ho...@gmail.comwrote:

 Did the field2 have an initial value or did you set the value in your
 browser and then let the ajax run?

 Hielke

 On 21 Dec 2010 20:51, eugenebalt eugeneb...@yahoo.com wrote:
 
 
  I have a piece of Ajax code, attached to some field (let's call it
  sourceField), which looks like this:
 
 
  sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
  {
 
  protected void onUpdate(AjaxRequestTarget target)
  {
target.addComponent(Field2);
  }
  }
 
 
  As you can see, Field2 is not changed in any way, it is not cleared or
  modified (so this code shouldn't really do anything).
 
  However, when this Ajax runs on changing the sourceField, the Field2's
  values get erased! Field2 is actually a CheckBoxMultipleChoice, and all
 the
  checkbox selections get erased as soon as I do target.addComponent().
 
  Why does this happen? Any ideas on what's causing this?
 
  (Field2 is a CheckBoxMultipleChoice, initially initialized with some
 list,
  and its outputMarkerId = true, to make it work with Ajax.)
 
  Thanks
  --
  View this message in context:

 http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159543.html
  Sent from the Users forum mailing list archive at Nabble.com.
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 




-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Pedro Santos
On Tue, Dec 21, 2010 at 5:50 PM, eugenebalt eugeneb...@yahoo.com wrote:


 I have a piece of Ajax code, attached to some field (let's call it
 sourceField), which looks like this:


 sourceField.add(new AjaxFormChoiceComponentUpdatingBehavior()
 {

 protected void onUpdate(AjaxRequestTarget target)
 {
   target.addComponent(Field2);
 }
 }


 As you can see, Field2 is not changed in any way, it is not cleared or
 modified (so this code shouldn't really do anything).

 However, when this Ajax runs on changing the sourceField, the Field2's
 values get erased! Field2 is actually a CheckBoxMultipleChoice, and all the
 checkbox selections get erased as soon as I do target.addComponent().

 Why does this happen? Any ideas on what's causing this?


Actually I have, but very unlikely:

 sourceField = new CheckBoxMultipleChoice(id, new MyModel(){ getObject{
return new ArrayList();} }, choiceList);

this would generate your problem :-)


 (Field2 is a CheckBoxMultipleChoice, initially initialized with some list,
 and its outputMarkerId = true, to make it work with Ajax.)

 Thanks
 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159543.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Pedro Henrique Oliveira dos Santos


Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread eugenebalt

Thanks for the fast replies, much appreciated, but what should I change in my
code? I'm still not clear.

Yes, the Field2 had some initial values with which it was constructed.
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159605.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread Igor Vaynberg
s/AjaxFormChoiceComponentUpdatingBehavior/AjaxFormSubmittingBehavior/
so all values are propagated

-igor

On Tue, Dec 21, 2010 at 10:24 PM, eugenebalt eugeneb...@yahoo.com wrote:

 Thanks for the fast replies, much appreciated, but what should I change in my
 code? I'm still not clear.

 Yes, the Field2 had some initial values with which it was constructed.
 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159605.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 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: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread eugenebalt

But I can't use AjaxFormSubmittingBehavior (correct me if I'm wrong).

I need to make some changes to Field2 prior to any form submission, they
have to be made as soon as the sourceField has changed in any way.

I just don't want the Field2's values to get erased without me even doing
anything. I was going to make some other changes to Field2, but noticed the
values were getting erased.

So I can't wait till form submission.
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159666.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: target.addComponent(Field) in Ajax erases that Field's values

2010-12-21 Thread eugenebalt

It looks like I fixed it by adding new Ajax code to Field2. 

The Field2's Ajax code does nothing, it just calls target.addComponent() on
itself: target.addComponent(Field2). This got rid of the values getting
erased.

So whenever you update something via Ajax, it has to be 2-way? You need to
attach Ajax not just to the caller but also to the target? thanks
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/target-addComponent-Field-in-Ajax-erases-that-Field-s-values-tp3159543p3159688.html
Sent from the Users forum mailing list archive at Nabble.com.

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