Form Field Order, with custom fieldfactory

Hey all,

I’ve browsed the forum for hours on end, seen at least 5 other threads like this one, yet none that depicts exactly what I’m trying to do or fix.

I’m hoping I can explain it without too much code since it would require me to post several entire classes. I would be willing to, but I’m hoping I can do without :slight_smile:

In short, here’s the situation:
I am creating a Vaadin app based on an existing database with ‘loads’ of data. So I have to work around some legacy things.

I have a bean for which I want to create a form. So far no problems.

Within this bean, from a historical point of view there are 3 fields that contain ID’s that represent another type of bean (you know, the many-to-one type of link without this link being present in the database, don’t ask why…). So within my form I want, for these id-fields to have a combobox containing the possible objects for which the ID has to be stored within my bean. (eg: person-pojo with a city-id, where the combobox for the city-id actually contains the city-objects and shows the city-names)
Creating these comboboxes is not an issue as I’m using my customfieldfactory. I am also able to link the id for my bean with the corresponding combobox selection (hooray for me)

The thing is, I am unable to influence the order in which my fields are shown in the form.

I have tried the “setVisibleItemProperties” method on the form. I have checked and double-checked the names of my fields for the object collection. Yet this doesn’t work. It still shows the fields in an alphabetical order.

Is there something within my customFieldFactory that I need to do?

Thanks in advance for your time!

Pieter

Hi,

My first guess is that you’re calling the setVisibleItemProperties() before you bind the form to the bean. You must call it after that.

The proper order is:

[list=1]

[]
Set the form field factory
[
]
Set the item data source
[*]
Set the visible item properties, which also sets the order

[/list]As is done
here
.

Hi Marko,

it is indeed as you said. (though your link does not contain a custom fieldFactory :glare: )

The issue I had was that I instantiated my form when the window was loaded (including fieldfactory & visible item properties) but the bean-binding to the form (and the making visible of the form) was done later based on decisions made within the window.

So I bow my head to you kind Sir and thank you for enlightening me -_-

I would recommend using the Form.setItemDataSource(item, propertyIds) method instead of doing the points 2 and 3 separately - that way you avoid possibly re-creating the fields when doing 3. You could then write a helper method for setting the data source with the visible properties if doing it from multiple locations.

Hey Henri,

thanks for your time & effort :slight_smile:

I have already modified the code so that points 2 & 3 are done in a
‘setter-method’
that is being called from outside the form (a parent-container which also contains the decision-making components that decide which bean is to be linked to the form)

but yes, combining them does sound interesting.

regards,
P.