PDA

View Full Version : [CLOSED] Hosted mode layout not working



algesten
10 Sep 2008, 11:38 PM
Platform: Mac OS X, Java 1.5.0_13
GWT: 1.5.2
GXT: 1.0.1
Safari: 3.1.2

The following code displays badly in hosted mode.


public void onModuleLoad() {

Viewport viewport = new Viewport();
viewport.setLayout( new BorderLayout() );

LayoutContainer north = new LayoutContainer();
north.add( new Html("North") );
viewport.add( north, new BorderLayoutData(LayoutRegion.NORTH, 33) );
north.setStyleAttribute("background", "red");

LayoutContainer west = new LayoutContainer();
west.add( new Html("West") );
viewport.add( west, new BorderLayoutData(LayoutRegion.WEST, 100, 50, 250) );
west.setStyleAttribute("background", "blue");

LayoutContainer center = new LayoutContainer();
center.add( new Html("Center") );
viewport.add( center, new BorderLayoutData(LayoutRegion.CENTER) );
center.setStyleAttribute("background", "green");

RootPanel.get().add( viewport );

}
Hosted mode:

http://web.mac.com/algesten/gxt/hosted.png

If I press the "compile" button in the hosted mode browser I launch Safari and it looks correct:

http://web.mac.com/algesten/gxt/browser.png

Not sure if this is a GXT, GWT or Mac OS X specific problem.

algesten
11 Sep 2008, 1:32 AM
Workaround

The problem has something to do with that LayoutData is set in Component by a Java method , whilst it is being read by JSNI.

Layout.insert(Widget widget, int index, LayoutData layoutData) is using Component.setLayoutData() to set the data on the component.
Layout.getLayoutData() uses the JSNI implemented method WidgetHelper.getLayoutData(c) to read it.

This workaround uses JSNI for both setting and reading:


public void onModuleLoad() {

Viewport viewport = new Viewport() {
@Override
public boolean insert(Widget widget, int index, LayoutData layoutData) {
Component component = wrapWidget(widget);
if (layoutData != null) {
WidgetHelper.setLayoutData(component, layoutData); // use JSNI to fix hosted mode problem
}
boolean added = super.insert(component, index);
return added;
}
};
viewport.setLayout( new BorderLayout() );

LayoutContainer north = new LayoutContainer();
north.add( new Html("North") );
viewport.add( north, new BorderLayoutData(LayoutRegion.NORTH, 33) );
north.setStyleAttribute("background", "red");

LayoutContainer west = new LayoutContainer();
west.add( new Html("West") );
viewport.add( west, new BorderLayoutData(LayoutRegion.WEST, 100, 50, 250) );
west.setStyleAttribute("background", "blue");

LayoutContainer center = new LayoutContainer();
center.add( new Html("Center") );
viewport.add( center, new BorderLayoutData(LayoutRegion.CENTER) );
center.setStyleAttribute("background", "green");

RootPanel.get().add( viewport );

}

algesten
11 Sep 2008, 2:53 AM
And the problem is fixed with 1.0.4 that is compiled against GWT 1.5.2.

Most likely down to something about JSNI code compiled with 1.4.x not being compatible with code compiled in 1.5.2.

Just get the latest version.

*kicks self for wasting everyone's time*

darrellmeyer
11 Sep 2008, 5:38 AM
No problem, I am glad the issue went away.