I take it your class A and B here are your POJO or Domain objects that you
use to set/get via Wicket models.

What model do you set to the component that doesn't update with your user
input?

~ Thank you,
  Paul Bors

-----Original Message-----
From: Nick Pratt [mailto:nbpr...@gmail.com] 
Sent: Monday, December 10, 2012 2:04 PM
To: users@wicket.apache.org
Subject: Re: Form submit with Collection<Child>

I have the following entities:

class A {
int someOtherVal;
String foo;
List<B> b;
}

class B {
int someVal;
}

Ive created a form to edit an instance of A.  I want the form to be able to
add/remove instances of B from the A.b collection.  Ive tried using
different repeaters (started with ListView, setReuseItems(true) and
listView.removeAll() in the click handler for the add-link. However, in
form.onSubmit, the collection values of the Entity A (i.e. the 'b' values I
created and added to A.b) are not applied to the IModel accessible in the
onSubmit handler, thus Im unable to add new 'B' entities to the A.b
collection.

Other form values like A.foo and A.someOtherVal are all correctly updated in
the form submit ( I see the entity A loaded from the DB (via an LDM),
A.setSomeOtherValue(), and A.setFoo() being invoked). I dont see any access
of setB() etc.

N

On Mon, Dec 10, 2012 at 1:35 PM, Paul Bors <p...@bors.ws> wrote:

> I for one can't follow your example but sounds to me that you are 
> setting your model on the form and are using collections.
>
> First use-case like that which comes to my mind is a list of selected 
> radio and check boxes or multiple selections in a select box.
>
> Using Wicket you shouldn't have to work too hard on updating the model 
> object (be it a collection) to update it with the user input. Wicket 
> should do that for you and if it's not working you might be doing 
> something wrong or forgetting something else.
>
> I would suggest to take a look at how CollectionModel is used:
>
> http://www.wicket-library.com/wicket-examples/compref/wicket/bookmarka
> ble/or
> g.apache.wicket.examples.compref.PalettePage?0
>
> Perhaps that can aid answering your quest.
>
> Otherwise, please better phrase your question and/or submit some code 
> examples to help us better understand.
>
> ~ Thank you,
>   Paul Bors
>
> -----Original Message-----
> From: Nick Pratt [mailto:nbpr...@gmail.com]
> Sent: Monday, December 10, 2012 1:11 PM
> To: users@wicket.apache.org
> Subject: Form submit with Collection<Child>
>
> My understanding of Form submit behavior with models is that onSubmit, 
> Wicket loads the model, and then applies all the changed form values 
> to that model.  This works fine for non-collection types (Strings, 
> ints etc) set from all the input types Ive been using (TextField, 
> RadioChoice, DDC etc.).
>
> However, what is not working is the addition of new Entities that live 
> inside a Collection of the IModel entity.  Lets say I have a 1..N 
> relationship, A..B, and I want to add 2 new Bs to A's collection (a 
> fairly common requirement) in my form. I dont want these new B entities
persisted
> in the DB until the entire form is submitted (Im using JPA cascade).   How
> do I code this part of the form/logic so that when I hit submit, I get 
> those
> 2 new B entities added to the A.b collection, so that I can save(a) 
> and have everything update?
>
> Regards
>
> Nick
>
>
> ---------------------------------------------------------------------
> 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

Reply via email to