Pages

Showing posts sorted by relevance for query gwt. Sort by date Show all posts
Showing posts sorted by relevance for query gwt. Sort by date Show all posts

Wednesday, April 15, 2009

GWT Concepts – No Multiple Pages

Here is the first thing that is not obvious for newcomers to GWT: There are no multiple pages involved in development. I was wondering, just like many others I guess, how to add another page to my GWT application. The answer from com.googlegroups.google-web-toolkit is below. It will take some time to get used to it. And I still hope this changes in the near future.

“I am new to GWT, though I have dabbled in C#/Java before so the language itself doesn't boggle me that much, but it seems some of the simpler concepts aren't sticking. Im pretty sure the answer to my question is so obvious, as I have not seen it answered in any of the tutorials on GWT on the web. What I wanted to know is, how do you do page navigation in GWT? For example I have my new class, with its onModuleLoad function, which is fine, but say I want to click a link and load a new page with a different onModuleLoad function? “

As others have pointed out, the Right(TM) way to do this is using the History mechanism. There are many strategies for working this into your application's internal syntax and structure. However, there are a few other basic concepts I think you might want some clarification on.

First, you should think of your GWT app as a single HTML page, in which user and application events cause PORTIONS of the page (ie DOM elements) to change, be replaced, or loaded with content from the server or internal application logic. In general you will not be sending the user/browser to another "real" URL. Your initial HTML page is basically a canvas on which your GWT application spews up content in response to user or server events (the typical AJAX model).

In the example of your login function, when your app has successfully received authentication credentials from the user, its next job will be to kick the login widgets off the page, and replace them with "whatever is next".

Second, you will probably find that the majority (if not all) of your user navigation paths are not coded in raw HTML. The GWT ui classes provide all the event handling and navigational connectivity that you would find in a typical desktop application. Although it is possible use raw HTML links to navigate your application, the GWT widgets are much easier to work with, test, and maintain than raw HTML files. So instead of following an <a href="blah blah">blah</a> and "going somewhere else", you will create event listeners that respond to mouse or key clicks which cause your app to change what is already there.

Finally, you typically will only have one EntryPoint implementation with an onModuleLoad method in your application. That class will be responsible for initializing your application - probably by creating classes for the UI, classes for handling UI events, and classes for managing your applications internal state. In a lot of the samples, the class which implements EntryPoint also implements all of the UI, the event handlers, and the application logic, but that's only to reduce the amount of code you have to read. In any serious application you will want to factor those things out into different classes (as in MVC).

It might be helpful to think of your EntryPoint.onModuleLoad() as if it were simply the main() method of a more traditional application.

GWT Project Basics

GWT projects consist of three elements:

  1. Module, module-name.gwt.xml
  2. Host, module-name.html
  3. Code, module-name.java

Module defines the entry point, which is found inside the code file. After creating the code file, add line similar to:
<entry-point class="MyProject.client.MyCodeClass" />
to the module XML file.

The code file implements the EntryPoint interface. This file contains onModuleLoad() function, which is similar to main() in C or Java. Additional classes can be implemented as simple Java classes. They should import needed com.google.gwt.core.client namespaces. This is done automatically by Eclipse. The resulting code for the application is very similar to C# or Java. The only thing missing is the designer support for UI classes. It would be extremely nice to have a designer to produce user interface and event linking automatically and/or visually.

HTML file contains a link to generated JavaScript file(s). This link is created automatically if you use Eclipse and GWT plugin. During the creation of HTML file in Eclipse there is an option to select the module(s) to be used. All the modules in the project get included in the HTML file by default. You should include only the modules that will be actually used on the host page. The other code files (.java) can be shared among different modules. HTML files can be left blank if the UI is to be manipulated completely in code, or it can contain some UI elements as well. These are usually only containers that will contain other elements which will be defined in code. One HTML host page can host multiple GWT applications. In that case, each application should have its separate container and not use the whole RootPanel (page body).

GWT Resources

Here is the reference in order to use GWT successfully…

Tuesday, April 14, 2009

Ajax on Java

Since I’m working on a web application, using Java, I’m looking to enhance the functionality using Ajax on the client-side. So, the focus turns to a part of my development environment I wasn’t paying attention to – Google Web Toolkit.

It offers the developers to develop the AJAX front-end by developing it in Java. This allows for edit-refresh-view cycle we’re used to. It also allows for easy debugging by stepping through the code. Using GWT’s built-in web browser allows the developer to view the changes in code effective immediately, just by refreshing the edited page. GWT then compiles the code into client-side JavaScript. The compiled JavaScript is highly optimized and is supposedly better than hand-maintained code.

If you’re looking for more detailed list of features, check the GWT Overview.

Tuesday, April 29, 2008

GWT with C# = Script#?


Nikhil Kothari's Weblog : Script#

Greg reminded me yesterday of Google Web Toolkit (GWT). And that's exactly what I was working on, even had the html page open. The point is to have all the active content happen on the client side as I don't have processing capability on the server side for my personal site. And, I just thought that JavaScript is mature enough for something like that.
So, here's the link to Script#. I'm going to play with it today.
It's a tool that compiles C# code into JavaScript. Applications can be created that run in a web browser. The data is available online - pictures, rss feeds, xml files...