Best practice to add user code inside CustomComponent

Hi guys,

I’m developing a little application with Vaadin using the Visual Designer provided by the Vaadin Plug-In for Eclipse. My first CustomComponent is working properly, but I would like to know if there is a best practice to add user code in addition to the “@AutoGenerated” parts?

At the moment every CustomComponent has a new private method named “customizeComponents()” that is called at the bottom of the constructor. “customizeComponents()” includes all the things, that are not covered by the Visual Designer. That works without problems, but I don’t like it very much, because the code gets forked what decreases maintainability.

Is there a better solution or even a design pattern?

Thanks for help and keep on working, Vaadin is great! :slight_smile:

The current Visual Designer does not support much manual customization of what it generates.

With Vaadin 7, you can use FieldGroup to link your fields to data sources etc, typically reducing the amount of custom code needed (one or a few lines in the constructor to do the binding).

Another idea: using your own subclasses of the standard components instead of the standard ones directly. This approach has limitations in the visual editor, though.

In theory, the Visual Designer could e.g. interact with Java code in a more complex manner so that custom code would be preserved, but in practice that would be very complicated and error prone, likely to break or remove user code without it being clear to the user. The editor is open source, though if you have good ideas and the time to implement them.

Concrete suggestions on smaller improvements are also welcome - perhaps first here on the forum and then as tickets.