Reflection in vaadin

Reflection in vaadin

Hello :slight_smile:
I wonder if vaadin works with reflection, if by instantiating a class dynamically.

Giving the name from a database.

regards :smiley:

You should be a little more specific about what you mean. I presume you mean something like using class.newInstance(). I haven’t seen anything that would prevent reflection from working. However, I don’t know why you would want to do that with Vaadin classes. There’s a limited set of relevant classes and it would probably be better to do something like the following pseudo code:

if (x == y) then {
new TextField();
} else if (x==z) then {
new Label();

Sorry for not letting more details :*)
I want to use the reflection to create a dynamic menu in vaadin bringing the class name and the names of the menus of the database. For this I wonder if I can vaadin instantiate a class from its name.
regards :smiley:

Vaadin easily supports creating a menu dynamically with the menu item descriptions coming from the database. You also attach actions to menu items that get executed when the menu items is selected. It sounds like you want to use reflection when the item gets executed. What happens in an action is not necessarily Vaadin specific and anything that Java allows can be performed.

I wonder if I can provide an example, I still have not found anything to help me with my problem.


There is nothing special in Vaadin that prevents you from using Java reflection. Make sure that you properly initialize your custom class loader to read class bytecodes from the database or whatever location you want.

Thanks for the support, and solved my problem.

regards :grin::bashful::blink: