Frage

Is it possible to create a multi-module application with GWT? What i mean is, to create 2 module, one for front-end website, one for admin management that manage the front-end website. Hope you understand my approach :)

War es hilfreich?

Lösung

It's possible, but it isn't so self-evident, as you have to make modifications of the default project layout in a few places (rename-to attribute, entry-point classname, script-src, compiler arguments). So I believe, this is a valid question.

I assume you want to do this, because you'd like to share code between the two web pages. There are a few alternatives to achieve this, the easiest one is probably this:

Single project, two URLs

You need two module xml files, and two html files.

FrontEnd.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='frontend'>
  <inherits .../>
  <entry-point class='org.example.FrontEndEntry'/>
  ...
</module>

Admin.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='admin'>
  <inherits .../>
  <entry-point class='org.example.AdminEntry'/>
  ...
</module>

FrontEnd.html

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    ...
    <script type="text/javascript" language="javascript"
       src="frontend/frontend.nocache.js"></script>
  </head>
  ...
</html>

Admin.html

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    ...
    <script type="text/javascript" language="javascript"
       src="admin/admin.nocache.js"></script>
  </head>
  ...
</html>

Then, when compiling the GWT app, just add both modules at the end of the command line (or in an IDE like Eclipse, select both when compiling). Same for launch configurations.

Andere Tipps

A module is loaded as a javascript file called sample/sample.nocache.js. You can have the servlet serve different html files with different js files(modules) based on the url or if the user is logged in. You will need to compile each module separately.

Google resources on this: Dynamic Host Page, Organising Modules

You can also include multiple modules on the same page but be careful with this because you don't know what order they will load in.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top