如何在Vaadin中获取HTML Elmement(或DOM)?
在GWT中,我可以通过方法在我的Vaadin组件上DOM.getElementById("myId");
设置id属性setId()。例如:
Button button = new Button("Say Hello");
button.setId("myButton");
Run Code Online (Sandbox Code Playgroud)
因此,如何在Vaadin中检索此DOM元素?
您可以使用此:
public static Component findComponentById(HasComponents root, String id) {
for (Component child : root) {
if (id.equals(child.getId())) {
return child; // found it!
} else if (child instanceof HasComponents) { // recursively go through all children that themselves have children
Component result = findComponentById((HasComponents) child, id);
if (result != null) {
return result;
}
}
}
return null; // none was found
}
Run Code Online (Sandbox Code Playgroud)
来源:https : //vaadin.com/forum/#!/ thread/ 3199995/3199994