开发者

including gwt widget in a jsp

I was wondering if anyone could please help me. I'm quite desperate. I've been trying to find out how to add a gwt widget to a jsp page. I've looked online and it said to use the

<div id="wherethegwtwidgetgoes"> 
</div> 

RootPanel.get("wherethegwtwidgetgoes").add(widget); 

However I'm not too sure what that even means. For simplicity, lets just say I wanted to add a decorative panel. how would I do that? Here is a link to it :

http://gwt.google.com/samples/Showcase/Showcase.html#!CwDecoratorPanel

Sorry, I am super stuck and have been super busy with compilation systems and have not been able to look thoroughly into the gwt controls and layering. I would greatly appreciate help. If someone could answer this. My code project is significantly more complicated, but I learn by seeing examples. 开发者_运维知识库

Could someone please help me with this? Thanks so much


You need to read up on GWT. Do the first example project and you'll understand. Here's the quick process to getting your tools.

  1. Download Eclipse
  2. Install GWT Plugin for Eclipse
  3. Start a new GWT Web Application Project
  4. In the EntryPoint extension class, you put the RootPanel.get("wherethegwtwidgetgoes").add(widget).
  5. Compile the project
  6. Deploy the project

If you want to understand all the pieces, you need to read the tutorials online. It'd be just as fast as asking the question on here.

RootPanel.get() - Retrieves the body element from the webpage

RootPanel.get('elementID') - Retrieves the element with the id passed to the get function, in this case it returns the element with id="elementID".

RootPanel.get().add(widget) - Adds a widget control to the element you retrieved.

The compiler then turns your code into javascript and other stuff it'll need. If you look under the html file generated by eclipse, you'll see a javascript tag that includes a .js file. This .js file is the compilation of your project. You'll need to include that as well.

I'd highly suggest doing this quick guide. It'll answer a lot of questions.


David, the tag goes in the html code, or in your case, the jsp page (which will be redered as html later).

The RootPanel.get part goes in the Java code that after compilation will became JavaScript.

When it goes to production, the html (or jsp, whatever) will call the JavaScript that was generate by GWT. Then the RootPanel.get will look for the tag in the html with id "wherethegwtwidgetgoes" and will place the widget inside that div.

Setting up the environment to work with GWT is quite cumbersome but important to get it right. Take your time and read some tutorial about setting the environment properly.


I've been working on some semi-complex wrappers in GWT for JSP pages. The way I've been doing it is this:

Let the JSP page load. On the GWT entry point, It calls some specialized wrapper classes that grab a div, and adopt it as a GWT element, effectively making the JSP page a GWT widget. Also, I've found it's best to use Document.get().getElementById("divid") to load the element and make some sanity checks (In my case, it finds all the images in a div, checks to see if they are loaded, and if not, attaches a loadhandler to them) before using RootPanel's get. RootPanel's get can sometimes do some adopting that makes things complicated with "Element already added" exceptions. Also, I do this because I need to actually use RootLayoutPanel, and things get much more complicated when trying to add a widget to a GWT page in that case, as RootLayoutPanel doesn't provide the option to get an element by id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜