martes, 23 de agosto de 2011

GWT - Organización de proyectos & compatiblidad con las librerias Java

Una URL muy util sobre como organizar nuestros proyectos en GWT es:


Individual units of GWT configuration are called modules. A module bundles together all the configuration settings that your GWT project needs:
  • inherited modules
  • an entry point application class name; these are optional, although any module referred to in HTML must have at least one entry-point class specified. Es la clase que extiende de EntryPoint.
  • source path entries: Son los archivos que luego seran traducidos a JavaScript
  • public path entries: Lugar donde se colocaran todos los recursos estáticos como imágenes, CSSs, etc.
  • deferred binding rules, including property providers and class generators


Creación de un modulo diferente (otro proyecto) con clases que necesitamos usar en el modulo GWT

Creating a second module doesn't necessarily mean that that module must define an entry point. Typically, you create a new module when you want to package up a library of GWT code that you want to reuse in other GWT projects. An example of this is the Google API Library for Google Web Toolkit (GALGWT), specifically the Gears for GWT API binding. If you download the library and take a look at the gwt-google-apis/com/google/gwt/gears you'll find the Gears.gwt.xml file for the module which doesn't define an entry point. However, any GWT project that would like to use Gears for GWT will have to inherit the Gears.gwt.xml module. For example, a module named "Foo" might want to use GALGWT, so in Foo.gwt.xml an <inherits> entry would be needed.

Por ejemplo, si las entidades de dominio estan en otro modulo diferente (proyecto diferente) al del modulo de GWT, entonces hay que crear un modulo gwt (somemodule.gwt.xml) en el modulo que necesitamos (en el de entidades de dominio) y agregar la dependencia (<inherits name="somemodule"/>) en el modulo donde queremos usar esas entidades (es decir, en el modulo GWT agregamos el tag inherits).



Para el caso de librerias de terceros (third parties) en un modulo GWT: 

Al agregar un JAR (que sea de GWT) como así tambien la dependencia de un modulo:

En el XML (modulo GWT) del modulo en cuestión (Ej  modulePrincipal.gwt.xml) agregar <inherits
name='com.thapar.gwt.user.ui.SimpleDatePicker'/>

El "com.thapar.gwt.user.ui.SimpleDatePicker" corresponde al XML (modulo GWT) del JAR.

Todo JAR a priori tiene que tener el XML (modulo GWT).



Subset de la JRE que son emuladas por la JRE de GWT


Ejemplo de un XML que identifica a un modulo GWT

StockWatcher.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='stockwatcher'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>


  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <!-- <inherits name='com.google.gwt.user.theme.clean.Clean'/>-->
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
   <inherits name='com.google.gwt.user.theme.dark.Dark'/>     


  <!-- Other module inherits                                      -->


  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.google.gwt.sample.stockwatcher.client.StockWatcher'/>


  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>
  
  <!-- Especificando el LOCALE -->
  <extend-property name="locale" values="de"/>


</module>


<inherits name="logical-module-name" /> 
Para heredar clases de otros modulos para que se traduzcan a Javascript

<entry-point class="classname" /> 
 Especifica el EntryPoint Class. En caso que haya varias, estas seran ejecutadas en orden de aparición.

<source path="path" /> 
Any Java source file appearing in this subpackage or any of its subpackages is assumed to be translatable

<public path="path" />
Any file appearing in this package or any of its subpackages will be treated as a publicly-accessible resource

<servlet path="url-path" class="classname" />
For RPC, this element loads a servlet class mounted at the specified URL path. The URL path should be absolute and have the form of a directory (for example, /calendar). Your client code then specifies this URL mapping by annotating the service interface with the @RemoteServiceRelativePath attribute. Any number of servlets may be loaded in this manner, including those from inherited modules.
NOTE: as of GWT 1.6, this tag does no longer loads servlets in development mode, instead you must configure a WEB-INF/web.xml in your war directory to load any servlets needed.

<stylesheet src="css-url" />
Automatically injects the external CSS file located at the location specified by src


Compatibilidad de GWT con las librerias de java

Ver este link que es muy claro: 
http://code.google.com/intl/es/webtoolkit/doc/latest/DevGuideCodingBasicsCompatibility.html

No hay comentarios:

Publicar un comentario