Vaadin

Aus Peter Fuerholz' Wiki
Zur Navigation springen Zur Suche springen

Create first application

  1. Eclipse, Open EE perspective, create server, 'Apache', 'Tomcat 6.0', base directory is 'usr/local/tomact'
  2. 'File', 'New', 'Other...', 'Vaadin', 'Vaadin 7 project', enter project name etc.

URL parameters

?restartApplication
In some cases the application does not proper restart when restarting the server. (Might be connected with avoiding session serialization over Tomcat restarts. See web.xml to uncomment this feature.)
?debug
Show debug window.
This is e.g. very useful to see if the proper connector class is used. (If the proper client-class is not found its base class implementation seems to be used...)

Installation / Developing with Eclipse (for Eclipse Kepler)

  1. Eclipse: Help, Install New Software...
  2. Add Server: 'http://vaadin.com/eclipse', install all available plugins
  3. Select 'all available sites', install 'JST Server Adapters' (newest version)
  4. File, New Project, Vaadin Project, then create new server (Tomcat) and select the Vaadin version to use (will be downloaded instantly)

Installation / Developing with Eclipse (for Eclipse Indigo on Linux)

  1. Start Eclipse via sudo (nasty Eclipse problem in Indigo with Linux).
  2. Eclipse: Help, Install New Software...
  3. Add Server: 'http://vaadin.com/eclipse', install all available plugins
  4. Select 'all available sites', install 'JST Server Adapters' (newest version)
  5. OPTIONAL: Help, Eclipse Marketplace..., seek for Mongrel, install
  6. Terminate Eclipse
  7. Issue sudo chown -R pfu:pfu workspace/.metadata to change the file owner
  8. Start Eclipse (as normal user)
  9. OPTIONAL: Windows, Preferences, Mongrel:
    Select your Tomcat settings: Version: 'Tomcat 6.x', Tomcat home: '/usr/local/tomcat', select 'Context files', Context directory: '/usr/local/tomcat/conf/Catalina/localhost'
  10. File, New Project, Vaadin Project, then create new server (Tomcat) and select the Vaadin version to use (will be downloaded instantly)

OLD: New Server, Tomcat 6.0, installation directory: '/usr/local/tomcat'


Adding an Vaadin-AddOn to your Vaadin project

See [1]
As there can be seen under chapter 17.4.3 in the link above, following code snippet must be added to your web.xml:

 <init-param>
   <description>Widget Set to Use</description>
   <param-name>widgetset</param-name>
   <param-value>com.example.testvaadin7.widgetset.Testvaadin7Widgetset</param-value>
 </init-param>

The param value <param-value>com.example.testvaadin7.widgetset.Testvaadin7Widgetset</param-value> must be set appropriate to the *.gwt.xml-file contained in the Sources folder (without 'gwt.xml'). The gwt.xml-file may be created automatically by Eclipse/Vaadin-plugin when including the add-on. Nevertheless this may not work in all cases. Another way to do this is adding the library containing client widgets to an existing gwt.xml file, e.g.:

 <module>
   <inherits name="com.vaadin.DefaultWidgetSet" />
   <inherits name="org.vaadin.hene.expandingtextarea.widgetset.ExpandingtextareaWidgetset" />
 </module>

Typical workflow to create a Vaadin app with a Groovy backend

(These recommendations are specific to my personal settings.)

  1. Create all Eclipse projects under ~/workflow/git/FwApps
  2. Create the Groovy project and implement the business logic as a command line program which simplifies testing it. Set up logging using the logging framework built into the JDK (put my-logging.properties under /resource).
  3. Create Java interface classes within project FwToolsInterfaces.
    1. Implement an abstract class providing base implementation and provide fire.. methods.
    2. Depending on the case provide a test implementation. Thus, you can test your frontend without backend side-effects.
  4. Update the Groovy code to implement the newly interface from FwToolsInterfaces and firing the necessary events.
  5. Create a 'Vaadin' project and make following changes:
    1. When creating the project:
      • create new directory under ~/workflow/git/FwApps as base directory
      • Configuration: Vaadin, Java6(!), Servlet 2.4
      • Go through whole wizard ('Next...') which avoids refactorings afterwards...
    2. Remove vaadin-x.y.jar from WebContent/WEB-INF and add it from FwLibs.
    3. Start Vaadin app on server. You have to update the server settings so that the server contains all necessary Java and Groovy projects. (Recommendation: Copy existing server setting.)
  6. If you renamed your application class (or created another one an deleted the default one) you have to update WebContent/WEB-INF/web.xml.

Useful AddOns

Number-Field
Contains textfields for float and integer values. Unfortunately not (yet) available vor Vaadin 7! Alternative: Stepper
ExpandingTextArea
This textarea field extends visible rows as needed. I updated this widget to have it reduced to have only one row in minimum.

Helpful Articles

Compiling Widgetset With Eclipse Vaadin Plugin

The Widgetset must be compiled when client components got changed or newly implemented. Infos:

  • The compiling can be done within Eclipse (cog wheels icon in toolbar).
  • If the compiling does not work properly only a short message may be seen!
  • The log contains the java command line which enables to run the compiling on the command line. This is very helpful for debugging the compiling step:
    • Replace INFO by DEBUG for more debug information
    • add >log.txt to put output in file

If compiling fails check the following:

  • Run on command line and check output.
  • Check if additional libraries are properly added. (see chapter above)
  • Clean the GWT-cache. In Vaadin 7 / on my PC it can be found under /tmp/~gwt~
  • See Vaadin Troubleshooting


Compiling Widget Sets and *.gwt.xml

Vaadin bases fully on Google's GWT library to render the frontend. With GWT all GUI widgets can be implemented in Java and get compiled by the GWT compiler into JavaScript. Thus you can implement your frontend in your familiar programming language without the need of any browser plugins. Facts about the *.gwt.xml files:

  • The *.gwt.xml file got introduced by GWT and describes which Java classes need be compiled into JavaScript.
  • There can be more than one *.gwt.xml files but they shall be referenced forming a tree. The root .gwt.xml file shall be referenced in the web.xml file (up to Tomcat 6) or by means of annotating the Servlet class (Tomcat 7+).
  • Each Addon containing client code must have .gwt.xml file. If you want to use this Add-on you have to add this library to the classpath, reference the gwt.xml file in your base gwt.xml file and compile the whole widgetset. Example:
 <inherits name="com.neshendra.vaadin.addons.widgetset.NeshAddonsWidgetset" />
The update of your base gwt.xml file is possibly done automatically:
  • by Vaadin-plugin for Eclipse
  • by Gradle-plugin for Vaadin

Do mind:

  • A Vaadin-Addon-library needs to contain the client code as Java-code (uncompiled).
  • The gwt.xml-file, used stylesheets and some more meta information should be contained in the Addon's META-INF/manifest file. You can e.g. set this information by means of Gradle.
  • Your libraries MUST NOT contain any Servlets or gwt.xml files not intended for actual use: They may interfere your real application. (In my case an Addon contained a test-webapplication in its jar and thus could not be started at all!)
  • All your code to be compiled by the GWT compiler must be contained within a client folder. (Or even widgetset/client ? And the gwt.xml under widgetset?)