Search code examples
vaadinvaadin7

Vaadin : How to get Element by ID?


How to get HTML Elmement (or DOM) in Vaadin ?
In GWT I can use as DOM.getElementById("myId"); I can set id attribute on my Vaadin components by setId() method. For example:

    Button button = new Button("Say Hello");
    button.setId("myButton");

So, how can I retrieve this DOM Element in Vaadin ?


Solution

  • Vaadin 10 (Vaadin Flow)

    The new Vaadin Flow generation replaces the internal use of GWT for Web Components.

    This new architecture provides us with easy direct access to the DOM from the Java-based server-side, if you so desire. You can read the DOM, and you can manipulate elements in the DOM. Read about the new Element API in the manual.

    Vaadin 6, 7, & 8 (Vaadin Framework)

    This Answer expands on the comment by Vaadin expert, Henri Kerola.

    Vaadin is a server-side app framework. It's purpose is to shield the app developer from the details of HTML, CSS, JavaScript, DOM, GWT, HTTP, WebSocket, and such web technologies. The app developer writes in pure Java (and maybe a tiny touch of CSS for tweaking). Vaadin transparently and auto-magically generates the HTML-CSS-JavaScript-GWT-DOM necessary to render a representation of the app’s user-interface within a web browser.

    So there is no way to access the DOM from that Java server-side, nor any need to do so generally.

    If you want to take control of the web technologies then Vaadin is probably not the best framework for you.