tags:

views:

531

answers:

2

Hi

I want to get a nested div in GWT and be able to put a widget in there. Something like this:

<div id="container">
    <div id="content_left">
    </div>
    ...other divs
</div>

I want to be able to get content_left and put a widget in there. So far all RootPanel gets are the divs inside the tag. I also tried using DOM.getElementById(...) but I don't know how to put a widget as the add method specifies the input parameters should be of type child.

Now I don't know a lot about CSS and positioning and I didn't do the styling above. It's something I got from my graphic designer. I reckon this was his way of laying out things. I was already thinking about laying out without having to use an outer div such as the div with id=container above so I wouldn't have this problem in the first place but I'd like to hear if that's a good idea.

+1  A: 

GWT provides container widgets for this kind of thing: They generate your DIVs for you, and you can nest them to any depth in accordance with their own rules. You don't really need to use explicit DIVs for anything.

You said

Now I don't know a lot about CSS and positioning and I didn't do the styling above.

That's exactly what GWT is about: You don't need to. You put your GUI together in code and let GWT worry about how to translate it to CSS. Hint: It's much better at it than most of us will ever be. There are workarounds for many, many known browser quirks to make it as cross-platform as humanly possible.

Carl Smotricz
But the existing design of the webpage depends so much on his nested divs. Should I tell him to recode the webpage separating the static parts from the ones where I intend to use GWT?
Jeune
GWT gets one content root where it reigns supreme: there's no concept of doing GWT here and there in separate places. Maybe somebody else has a different opinion but I don't see a way to make your current design work well with GWT.
Carl Smotricz
What I meant was the design, the graphics. They're everywhere where I want to place a GWT widget. In this case they're also inside the div with id container. Now are u saying I should also layout my graphics in GWT for instance using the HTML widget or somehow through CSS using setStylePrimaryName? :D
Jeune
I think we're not communicating well, i.e. maybe missing each other's points, and I'm worried I may be giving you bad advice. I'm sorry but I think it would be best if I withdrew from this question.
Carl Smotricz
A: 

A specific example for the HTML snippet you provided would be something like this. FlowPanels are divs that support adding an arbitrary number of things to them. If you know that a given div will only ever have one widget in it, SimplePanel is probably a better choice.

Regardless though, in general what you want to do is take the HTML that you want to generate and build up the GWT code to output that particular DOM structure. A decent article on how I tend to deal with simpler widgets is tags first gwt.

FlowPanel container = new FlowPanel();
container.setStyleName("container");

FlowPanel contentLeft = new FlowPanel();
contentLeft.setStyleName("content_left");
container.add(contentLeft);

container.add(otherDivs);


//elsewhere in your code:
contentLeft.add(oneWidget);
contentLeft.add(secondWidget);
bikesandcode
Yes I have thought of this before but I have an issue with this, the GWT module loads a little bit later than the whole webpage/its static parts especially that I am doing an RPC call.
Jeune