PDA

View Full Version : Question regarding the Form Model


Catalin Sanda
Sep 20th, 2004, 05:33 AM
Hello,

I have a question regarding the NestingFormModel/SwingFromModel. What I need to do is to edit an object in a main form, which has a subform containing another object (a property from the object in the main form) of the same type (i’m trying to model a supervisor-employee type self-join). So here is what I do:

I create a nesting form model for my bean:
NestingFormModel nestingFormModel = SwingFormModel.createCompoundFormModel( nomenclatorBean );

I create a SwingFormModel which encapsulates the nomenclatorBean:
formModel = SwingFormModel.createChildPageFormModel( nestingFormModel, "Main Page" );

I register a new CustomPropertyEditor for my “supervisor” property and create a new SwingFormModel for that property:
formModel.registerCustomEditor( "supervisor",new NomenclatorLOVCustomPropertyEditor(SwingFormModel. createChildPageFormModel( nestingFormModel, "Supervisor", "supervisor" )));

In the CustomEditor I create a new form on which I try to bind components to the child form model, but the framework binds them directly to the parent object (employee) not the child object (supervisor). Both the employee and supervisor have a property called "code". The current implementation also creates problems when it comes to labels and validation error messages.

I would greatly appreciate a quick response, because we are working on a large 3-tier application and we are a little behind schedule.

Thanks in advance,
Catalin Sanda

oliverhutchison
Sep 20th, 2004, 11:29 PM
Catalin,

can you please post the code for NomenclatorLOVCustomPropertyEditor?

Thanks

Ollie

Keith Donald
Sep 21st, 2004, 01:44 AM
Here is a test case illustrating a similiar case to what you're trying to achieve:


public void testCompoundFormModel() {
CompoundFormModel formModel = SwingFormModel.createCompoundFormModel(new Employee());
** ConfigurableFormModel supervisorModel = formModel.createChild(
"supervisorPage", "supervisor");
SwingFormModel supervisorPage = new SwingFormModel(supervisorModel);
JTextField field = (JTextField)supervisorPage
.createBoundControl("name");
assertTrue(field.getText().equals(""));
field.setText("Don");
ValueModel name = supervisorPage.getValueModel("name");
assertTrue(name.getValue().equals("Don"));
supervisorPage.commit();
Employee emp = (Employee)formModel.getFormObject();
assertTrue(emp.getSupervisor().getName().equals("Don"));
}


I think the problem is you're not binding the supervisor child page model to the supervisor property of the root Employee bean. (see **above)

Also note: the binding infrastructure has been enhanced to allow for nested properties as part of the same form model. This greatly simplifies client code. NestingFormModels should generally only be used as part of a edit that spans multiple logical pages (for example, a wizard.)

Here's a simplified example, assuming all these form fields are on the same logical page:


public void testPageFormModel() {
SwingFormModel employeePage = SwingFormModel.createFormModel(new Employee());
JTextField field = (JTextField)employeePage
.createBoundControl("supervisor.name");
field.setText("Don");
employeePage.commit();
Employee emp = (Employee)employeePage.getFormObject();
assertTrue(emp.getSupervisor().getName().equals("Don"));
}