how to access the DOM gwt smartclient
To access the DOM of your page you can call
Document.get()
, which has a convenience method for finding an element by it's id Document.get().getElementById("test");
Of course, you should keep a reference to this element so as not to have to search through the DOM everytime you want to access it, because this is brutal.
private Element testDiv = Document.get().getElementById("test"); ... testDiv.setInnerHTML("Some html"); ... testDiv.setInnerHTML("Some other html");
But once you have a reference to this element, calling setInnerHTML is the most efficient way to do what you want. I'm not sure why you think this is brutal. This is probably even more efficient than when you call a method on a widget to change it's content, like
setText(" ...")
on a TextBox
for example, because these methods usually check the value passed as parameter for security.
Security could also be a concern for you, depending on what the user can do. But usually if a user can modify the HTML in your page that's a concern. You might want to look at GWT's SafeHTML feature.
If you're looking for RichText components, you can look at GWT's RichTextArea for example. But this type of component is usually not well supported by all browsers and will take more resources than what you're doing already so I don't recommend it.
Comments
Post a Comment