Hi all…
I’m building a Form that haves binds a POJO (Connection), and that POJO has references to another POJO(Database), like that:
class Connection {
String connectionName;
String username;
String password;
Database database;
}
class Database {
String databaseName;
String jdbcDriver;
}
I alread have a separated form, that managed the Database entity, and it is working nice. In the ‘Connection’ form, I have a Select component that shows the Databases avaliable, and it works too. If Im creating a new Entity, I piked a value from the select box, and the value is persisted fine.
But, if I want to modify a Entity, the database that is associated with the ‘Connection’ entity is not selected as default on the Select, or ComoBox as I tested.
Other fields, that uses TextField haves their values seted OK.
I try many things, like force the selection before the form is created, with
form.getItemProperty("database").setValue("databaseFromItem")
Im creating the field, with a custom FormFieldFactory:
private class ConexaoFieldFactory extends DefaultFieldFactory {
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
String pid = (String) propertyId;
if(pid.equals("sigla")) {
TextField t = new TextField("Sigla");
t.setRequired(true);
t.setRequiredError("Por favor, informe uma sigla");
t.addValidator(new StringLengthValidator("A sigla deve conter entre 3 e 20 caracteres", 3, 20, false));
t.setNullRepresentation("");
return t;
}
else if(pid.equals("databaseHost")) {
TextField t = new TextField("Host");
t.setRequired(true);
t.setColumns(20);
t.setRequiredError("Por favor, informe a classe HOST para este banco de dados");
t.setNullRepresentation("");
return t;
}
else if(pid.equals("database")) {
POJOContainer<Database> container;
DatabasesController controller = new DatabasesController();
List<Database> dbs = controller.getAllDatabases();
if(dbs.isEmpty()) {
container = new POJOContainer<Database>(Database.class, "sigla");
}
else {
container = new POJOContainer<Database>(dbs, "sigla");
}
Select t = new Select("Databases", container);
t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
t.setItemCaptionPropertyId("sigla");
t.setRequired(true);
t.setNullSelectionAllowed(false);
t.setMultiSelect(false);
return t;
}
return null;
}
}
My form is a custom form too, extended from the Form class, to override attachField, and position the fields freely.
Any help is apreciated. Ive read some topics on this forum, but nothing that I found solve my problem…
–
Eduardo Frazão