I raised query around a month ago about setting the width of the first column in a CellBrowser in GWT. There is a bug that stops this from occurring - it always displays with a default width of 200px because this is the generated HTML for the wrapper divs:
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; bottom: 0px; width: 200px;">
<div style="position: absolute; overflow: hidden; left: 200px; top: 0px; bottom: 0px; width: 8px;">
So as a work around I am trying to set the width style dynamically through the GWT DOM API. Here is some sample code showing my approach:
Button test = new Button("Test");
test.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Element browserElement = browser.getElement();
NodeList browserChildNodes = browserElement.getChildNodes();
for (int i=0; i<browserChildNodes.getLength(); i++) {
Node n = browserChildNodes.getItem(i);
int divCount = 0;
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element e = Element.as(n);
if (e.getTagName().equalsIgnoreCase("DIV")) {
System.out.println("Before mod: " + e.getAttribute("style"));
if (divCount == 2) {
Style s = e.getStyle();
e.setId("col1");
s.setWidth(400.00, Unit.PX);
e.setAttribute("style", "position: absolute; overflow: hidden; left: 0px; top: 0px; bottom: 0px; width: 400px;");
} else if (divCount == 3) {
e.setId("col1Dragger");
e.setAttribute("style", "position: absolute; overflow: hidden; left: 400px; top: 0px; bottom: 0px; width: 8px;");
}
System.out.println("After mod: " + e.getAttribute("style"));
divCount++;
}
}
}
}
});
However, when 'button Test is clicked, it makes no difference to the style attribute. The 'after mod' println shows the same results as 'before mod'. Checking the HTML, also shows no change.' I have also tried the above code in the initialization code for the CellBrowser; nothing changes in the rendered HTML.
I am sure I am looking at the right divs, as a println of the style attibute matches perfectly.
setId(), also has no effect.
I have also tried e.getStyle().setProperty("width", Unit.PX), and this had no effect.
Why is the DOM manipulation having no effect?