Reputation: 698
public Task {
private int id;
private Company sender;
private Company receiver;
//Getter and Setter
...
}
As you can see, I have 2 other custom classes in the task class. And a company has for example Adress and Directory (see screenshot below).
Upvotes: 0
Views: 470
Reputation: 16131
Make a panel for editing the Company
class and put two instances of it with different Model
s to the TaskPanel
public class TaskPanel extends Panel{
public TaskPanel(String id, IModel<Task> model){
super(id, model);
add(new CompanyPanel("senderCompanyPanel", new PropertyModel(model, "sender")));
add(new CompanyPanel("receiverCompanyPanel", new PropertyModel(model, "receiver")));
...
}
}
Upvotes: 1
Reputation: 20029
You could create a CompanyPanel
which takes a IModel<Company>
. You could use a PropertyModel on your task class to get one. PropertyModel sender = new PropertyModel(myTask, "sender")
. The panel then can have two TextFields for which you can use a CompoundPropertyModel on the IModel that is passed.
Reuse this panel twice on your form.
On the CompanyPanel
public class CompanyPanel extends Panel
{
public CompanyPanel(String id, IModel<Company> model)
{
super(id, new CompoundPropertyModel(model));
add( new TextField("address"));
add( new TextField("directory"));
}
}
Lookup the CompoundPropertyModel in the docs. It is really useful.
Upvotes: 3
Reputation: 10896
Just create a Panel or Fragment, make its model a IModel<Company>
, and add to your page two instances of it, one for sender
and another for receiver
.
Upvotes: 0