Setting data- attribute in GWT / Bootstrap

1.9k views Asked by At

I am working with GWT and implementing bootstrap through GWT-Bootstrap library.

I can't seem to find a way to add data- attributes to my elements?

I can do it by writing HTML directly:

HTMLPanel htmlPanel = new HTMLPanel("<button type=\"button\" class=\"btn\" data-custom=\"some-custom-data\">Hello World</button>");
menuControl.add(htmlPanel);

But that's just ugly and defeat the purpose of using GWT (might as well write a plain HTML code).

I am looking for ways to do something like:

Button button = new Button();
button.setText("Hello World");
button.setStyleName("btn");
// Fine up to here, but now i want:
button.setAttr("data-custom", "some-custom-data");
1

There are 1 answers

0
Ümit On BEST ANSWER

How about button.getElement().setAttribute("data-custom","some-custom-data"); ?