ok, I think I've figured out what you need. If you want to group two or more form fields in your custom form component you should extend class FormComponentPanel instead of FormComponent. This class combines the features of both a Panel (it has it's own markup file) and a FormComponent (it is a subclass of FormComponent). So for example PersonFormComponent will have the following code and markup:

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

markup:

<html>
....
<wicket:panel>
First Name:<input type="text" size="20" wicket:id="firstname"/>
Last Name:<input type="text" size="20" wicket:id="lastname"/>
</wicket:panel>
....
</html>

Now you can attach you custom component in your form as if it was a Panel. You can use a div or a span tag to attach it:


Form form = new Form("form");

form.add(new PersonFormComponent("personFormComponent"));

markup:

<form wicket:id="form">
  <div wicket:id="personFormComponent">
  </div>
<form>

Remember that if you don't like to have a div or a span in you final markup you can always call setRenderBodyOnly(true) on your custom component.
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?



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

Reply via email to