Bind data to form dynamically

Hi,
I want to build a form dynamically, knowing the bean and the fields at runtime. The superclass of the bean is GenericModel, but the bean is one of its derived classes.
In the array propertyNames I have the names of all properties of the bean

public void cretaBinder(GenericModel genericModel) {

Binder binder=new Binder<>(genericModel.getClass());

for (myProperty : propertyNames){

	TextField textField=new textField();
    
	binder.bind(textField,getter,setter);
    
}

}

How can I replace getter and setter, knowing the name of the property? I can get the getter and setter method by reflection, but bind wants a functional Interface ValueProvider.
How can I get getter and setter ValueProvider to be passed to bind?

Thank you

Hi,

You could try using something like
.bind(bean -> { return propertyDescriptor.getReadMethod().invoke(bean); }, // getter

(bean, value) -> { propertyDescriptor.getWriteMethod().invoke(bean, value); } ); // setter

I did not test this, but I think you will get the idea out of it. PropertyDescriptor is the descriptor for the Bean you get with reflection.

-Olli

Thank you Olli,
I find out that BindingBuilder has the method bind(String propertyName) that connects the field to the property with the given name. This is exactly what I need.
Thanks, Francesco