In data domenica 3 febbraio 2013 14:57:46, Lucio Crusca ha scritto:
> In data domenica 3 febbraio 2013 13:17:13, Andrea Del Bene ha scritto:
> > To clarify a bit more, you should end up writing something like:
> > 
> > <form  wicket:id="form">
> > 
> >    <input type="text"   wicket:id="formcomponentA" />
> >    <textarea  wicket:id="formcomponentB">...</textarea>
> > 
> > </form>
> > 
> >   and Java code
> > 
> > Form form = new Form("form");
> > 
> > form.add(new FormComponentA("formcomponentA"));
> > form.add(new FormComponentB("formcomponentB"));
> 
> Thanks, now it seems clear. Last doubt, what if I have two or more texts in
> either FormComponent? Shouls I repeat wicket:id="FormComponentA" for each
> one?

No, it's not clear to me once again, sorry, but the above suggestion does not 
fit the real case.

Let's make a more concrete example.

class Person
{
  String firstname;
  String lastname;
}

class PhoneNumber
{
  Person person;
  String dial;
  boolean mobile;
}

class PersonFormComponent extends FormComponent<Person>
{
  PersonFormComponent(Person p)
  {
    super("personFormComponent", new CompoundPropertyModel(p));
    add(new TextField("firstname"));
    add(new TextField("lastname"));
  }
}

class PhoneNumberComponent extends FormComponentModel<PhoneNumber>
{
  PhoneNumberComponent(PhoneNumber n)
  {
    super("phoneNumberFormComponent", new CompoundPropertyModel(n));
    add(new TextField("dial"));
    add(new CheckBox("mobile"));
  }
}

class PersonForm
{
  PersonForm(Person p)
  { 
   super("personForm");
   add(new PersonFormComponent("personFormComponent", 
                                new CompoundPropertyModel(model));
   PhoneNumber pn = findOrCreatePhoneNumber(p);
   add(new PhoneNumberFormComponent("phoneNumberComponent", pn);
  }
}

PersonForm.html:
<form wicket:id="personForm">
  First Name:<input type="text" size="20" wicket:id="????"/>
  Last Name:<input type="text" size="20" wicket:id="????"/>
  ...
  Phone Number:<input type="text" size="20" wicket:id="????" />
  Mobile?<input type="checkbox" wicket:id="????" />
</form>

What should I write in place of "????" ? If I put the FormComponents IDs then 
the CompoundPropertyModels won't find the fields to bind. If I put the beans 
fields names, then the PersonForm constructor won't find the IDs to bind the 
whole FormComponent subclasses.

Can you please show me the markup needed for the above example?

Reply via email to