Hello,
we have some troubles with displaying multiple text fields in a single row in a form.
According to this forum, the correct way is to create a sub form and then specify the HorizontalLayout for this one.
Here what we do in the main FieldFactory for the form:
else if ("Zip".equalsIgnoreCase(propertyId.toString()))
{
Form subForm= new Form();
// subForm.setCaption("PLZ/Ort");
HorizontalLayout hLayout= new HorizontalLayout();
hLayout.setWidth(COMMON_FIELD_WIDTH);
subForm.setLayout(hLayout);
subForm.setItemDataSource(item);
subForm.setFormFieldFactory(new ZipFieldFactory());
subForm.setVisibleItemProperties(Arrays.asList(
new String[]
{
"state", "zip", "city"
}));
So you see, we wish to show state/zip/city in one line.
Strange, this only work when in the Pojo Item all fields are NULL,
otherwise the whole sub form is not displayed.
We do only include the “state” field in the setVisibleItemProperties of the mainform.
The zip and city are not specified, because when we return NULL from the
factory, the component throws a NPE.
We also tested it that way:
Form subForm= new Form();
// subForm.setCaption("PLZ/Ort");
HorizontalLayout hLayout= new HorizontalLayout();
hLayout.setWidth(COMMON_FIELD_WIDTH);
subForm.setLayout(hLayout);
subForm.setItemDataSource(item);
Field fState = super.createField(item, propertyId, uiContext);
fState.setCaption(null);
fState.setWidth("2em");
Field fZip = super.createField(item, propertyId, uiContext);
fZip.setCaption(null);
fZip.setWidth("4em");
Field fCity = super.createField(item, "city", uiContext);
fCity.setCaption(null);
fCity.setWidth("10em");
subForm.addField(new String("state"), fState);
subForm.addField(propertyId, fZip);
subForm.addField(new String("city"), fCity);
But that did result in a sub form with not correctly sized form fields…