You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Xavier López <xa...@gmail.com> on 2009/11/10 15:24:24 UTC

Mapping an association with Models

Hi,

I'm wondering if I'm doing things straight regarding this subject.

I have an Entity A with PK properties a1, a2. There is another entity B with
PK properties b1, b2. Between them there is an association class AB (with PK
a1, a2, b1, b2). Let's suppose I have a Form for editing A objects, in which
the user can choose many B values by means of a CheckBoxMultipleChoice cbmc,
with model object and choice list of type List<B>.
In the form's submit method, I create as many as necessary AB objects,
combining selected B's id's with current A's id.

class APanel extends Panel(){

private List<B> selectedBs;

public APanel(){

}

Re: Mapping an association with Models

Posted by Xavier López <xa...@gmail.com>.
Hi,

Sorry, posted the previous one by error, this is what's missing in the code:


class APanel extends Panel(){
private List<B> selectedBs;
public APanel(){
    A a = getA();
    List<B> choices = getBChoices();
    cbmc = new CheckBoxMultipleChoice("id", choices);
    cbmc.setModel(new PropertyModel(this, selectedBs));
    Form f = new Form("form"){
        onSubmit(){
              List<AB> abs = a.getAB();
              abs.removeAll();
              for (B b : selectedBs){
                     AB ab = new AB(a, b);
                     abs.add(ab);
              }
              // a contains properly initialized ab elements
        }
    }
    f.add(cbmc);
}

Question is, does 'selectedBs' get serialized in pageMaps ? If so, I suppose
it would be better to store only selectedB's id's...

Thanks, and sorry again for the double-posting inconvenience !
Xavier