Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 1.23 KB

tutorial-user-input.asciidoc

File metadata and controls

30 lines (24 loc) · 1.23 KB

Retrieving User Input

Element textInput =  ElementFactory.createInput();
textInput.setAttribute("placeholder", "Please enter your name");

To get the value from the input to the server, you could use the event data feature described in the event listener tutorial but you can also ask the client to update the server side input element every time the value changes in the browser:

textInput.setSynchronizedProperties("value");
textInput.setSynchronizedPropertiesEvents("change");

Any changes in the listed properties will be synchronized to the server when any one of the listed events occur in the browser.

The synchronized properties can be retrieved using the Element.getProperty API so a button click listener looks like:

button.addEventListener("click", e -> {
    String responseText = "Hello " + textInput.getProperty("value");
    Element response = ElementFactory.createDiv(responseText);
    getElement().appendChild(response);
});