Directory

← Back

Guice Vaadin integration

Vaadin integration for Google Guice

Author

Rating

Popularity

<100

Guice Vaadin is the official Guice integration for Vaadin Framework.

Usage

setting up the servlet

first step is to set up the GuiceVaadinServlet, which needs a packagesToScan parameter holding the names of all packages that should be scanned for UIs, Views, ViewChangeListeners and VaadinServiceInitListeners. Sub-packages of these packages are scanned as well.

This can be done either by subclassing GuiceVaadinServlet and annotating it with @PackagesToScan, or by configuring a GuiceVaadinServlet in the deployment-descriptor.

configuration in java

    package org.mypackage;

    @javax.servlet.annotation.WebServlet(name = "Guice-Vaadin-Servlet", urlPatterns = "/*")
    @com.vaadin.guice.annotation.PackagesToScan({"org.mycompany.ui", "org.mycompany.moreui"})
    public class MyServlet extends com.vaadin.guice.server.GuiceVaadinServlet{
    }

configuration in xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <init-param>
            <param-name>packagesToScan</param-name>
            <param-value>org.mycompany.ui, org.mycompany.moreui</param-value>
        </init-param>
        <servlet-name>Guice-Vaadin-Servlet</servlet-name>
        <servlet-class>com.vaadin.guice.server.GuiceVaadinServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Guice-Vaadin-Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Scopes

Available scopes are UIScope and VaadinSessionScope, similar to what the Spring addon offers. UIScope is what MUST be the scope for all Vaadin-components, since they must belong to exactly one UI. VaadinSessionScope may be used to sync data between multiple tabs in the same browser.

import com.vaadin.guice.annotation.UIScope;

@UIScope
public class MyButton extends Button {
}

Guice-Module loading

Since Guice is configured via so called Modules, we need a way to load these modules. All Modules in the packages contained by 'packagesToScan' will be instantiated and loaded by default.

package org.mycompany.ui;

import com.google.inject.AbstractModule;

//will be loaded, since the 'org.mycompany.ui'-package is included in
//the packagesToScan  
public class MyModule extends AbstractModule{
    protected void configure(){
        //...    
    }
}

The alternative way to load modules is via the @Import-Annotation. This was introduced to make sort of an addon-development for guice-vaadin possible, similar to what Spring offers with it's own @Import-annotation.

First, a new Annotation is needed that points to the module to be loaded via @Import:

package org.mycompany.ui;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Target(ElementType.Type)
@Retention(RUNTIME)
@Import(SomeModule.class)
public @interface UseSomeModule {    
}

Second, the annotation is pinned on the servlet and that's it.

    package org.mypackage;

    @UseSomeModule
    @javax.servlet.annotation.WebServlet(name = "Guice-Vaadin-Servlet", urlPatterns = "/*")
    @com.vaadin.guice.annotation.PackagesToScan({"org.mycompany.ui", "org.mycompany.moreui"})
    public class MyServlet extends com.vaadin.guice.server.GuiceVaadinServlet{
    }

Copyright 2015-2017 Vaadin Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

updated dependencies to reflections and mockito

Released
2017-03-16
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.6+
Vaadin 7.0+ in 1.0.0
Vaadin 7.1+ in 1.1.4
Vaadin 8.0+ in 1.3.3-vaadin8
Vaadin 11+ in 2.3.6-vaadin10
Vaadin 10+ in 2.0.1-vaadin10
Vaadin 14+ in 2019.1-vaadin14
Browser
N/A

Guice Vaadin integration - Vaadin Add-on Directory

Vaadin integration for Google Guice Guice Vaadin integration - Vaadin Add-on Directory
Guice Vaadin is the official [Guice](https://github.com/google/guice) integration for [Vaadin Framework](https://github.com/vaadin/framework). ## Usage ### setting up the servlet first step is to set up the GuiceVaadinServlet, which needs a packagesToScan parameter holding the names of all packages that should be scanned for UIs, Views, ViewChangeListeners and VaadinServiceInitListeners. Sub-packages of these packages are scanned as well. This can be done either by subclassing GuiceVaadinServlet and annotating it with @PackagesToScan, or by configuring a GuiceVaadinServlet in the deployment-descriptor. ### configuration in java ```java package org.mypackage; @javax.servlet.annotation.WebServlet(name = "Guice-Vaadin-Servlet", urlPatterns = "/*") @com.vaadin.guice.annotation.PackagesToScan({"org.mycompany.ui", "org.mycompany.moreui"}) public class MyServlet extends com.vaadin.guice.server.GuiceVaadinServlet{ } ``` ### configuration in xml ```xml packagesToScan org.mycompany.ui, org.mycompany.moreui Guice-Vaadin-Servlet com.vaadin.guice.server.GuiceVaadinServlet Guice-Vaadin-Servlet /* ``` ## Scopes Available scopes are UIScope and VaadinSessionScope, similar to what the Spring addon offers. UIScope is what MUST be the scope for all Vaadin-components, since they must belong to exactly one UI. VaadinSessionScope may be used to sync data between multiple tabs in the same browser. ```java import com.vaadin.guice.annotation.UIScope; @UIScope public class MyButton extends Button { } ``` ## Guice-Module loading Since Guice is configured via so called Modules, we need a way to load these modules. All Modules in the packages contained by 'packagesToScan' will be instantiated and loaded by default. ```java package org.mycompany.ui; import com.google.inject.AbstractModule; //will be loaded, since the 'org.mycompany.ui'-package is included in //the packagesToScan public class MyModule extends AbstractModule{ protected void configure(){ //... } } ``` The alternative way to load modules is via the @Import-Annotation. This was introduced to make sort of an addon-development for guice-vaadin possible, similar to what Spring offers with it's own @Import-annotation. First, a new Annotation is needed that points to the module to be loaded via @Import: ```java package org.mycompany.ui; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Target(ElementType.Type) @Retention(RUNTIME) @Import(SomeModule.class) public @interface UseSomeModule { } ``` Second, the annotation is pinned on the servlet and that's it. ```java package org.mypackage; @UseSomeModule @javax.servlet.annotation.WebServlet(name = "Guice-Vaadin-Servlet", urlPatterns = "/*") @com.vaadin.guice.annotation.PackagesToScan({"org.mycompany.ui", "org.mycompany.moreui"}) public class MyServlet extends com.vaadin.guice.server.GuiceVaadinServlet{ } ``` Copyright 2015-2017 Vaadin Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Source Code

Guice Vaadin integration version 1.0.0
null

Guice Vaadin integration version 1.0.1
null

Guice Vaadin integration version 1.1.0
this version is not backwards compatible #non backward compatible changes ##removed @ViewScope The ViewScope annotation was removed because it is not neccessary, this behaviour can be achieved more easily in UIScope ##renamed @DefaultView to @ViewContainer DefaultView is a name already taken in the vaadin navigation realm, so it was renamed to avoid confusion #additional APIs there are two new annotations to load additional functionality to the guice context. Classes using this annotations need to reside in a package or under a package given in the 'basePackage' property of @Configuration to be loaded. ##added @UIModule to dynamically load Modules from external jars guice-vaadin is now able to load Modules from external jars, when they have the @UIModule annotation. ##added @GuiceViewChangeListener to enable attachment of ViewChangeListeners Classes implementing ViewChangeListener and annotated with @GuiceViewChangeListener will be automatically added to any navigator created by vaadin-guice.

Guice Vaadin integration version 1.1.3
#fixes fix for UI-Scope, ui-scopes should not overlap in VaadinSession, plus loads of unittests #features new AllKnownGuiceViews-Annotation that can be used to get all known GuiceView's injected, like ```java @Inject @AllKnownGuiceViews private Set guiceViews;

Guice Vaadin integration version 1.1.4
any Vaadin version upwards 7.1.0 may be provided, introduced a Guice Eventbus-derived GlobalEventBus that takes care of unregistering components after the session ended, some code reformatting

Guice Vaadin integration version 1.1.6
introduction of UIEventBus

Guice Vaadin integration version 1.1.8
new features: - SessionScope, bind your instances to the session - custom-navigator, implement your own navigator and have it used by guice also, some performance improvements and general code beautifications this will be the last release before 2.0, which will bring feature parity with vaadin-spring.

Guice Vaadin integration version 1.1.9
bugfix release, guice set to 4.0 for compatibility with repackaged guava version in vaadin

Guice Vaadin integration version 1.2.0-beta1
feature parity w/ spring-vaadin, some new api's, performance improvements etc.. this is a test version, do not use in production. latest stable version is 1.1.6.

Guice Vaadin integration version 1.2.0-beta2
new beta version for 1.2.0, latest stable is 1.1.6. new in beta 2: - fix view parameter issue

Guice Vaadin integration version 1.2.0-beta3
beta 3 for the version 1.2.0, fixes issue for GlobalEventBus and View-parameters. Latest stable version is 1.1.6.

Guice Vaadin integration version 1.2.0-beta4
beta 3 for the version 1.2.0, fixes issue for GlobalEventBus and View-parameters. Latest stable version is 1.1.6.

Guice Vaadin integration version 1.2.0-beta5
fix for NPE in VaadinSessionScoper. This is a beta version, the last stable version is 1.1.6

Guice Vaadin integration version 1.2.0
this release should bring feature parity with Spring, see description for details

Guice Vaadin integration version 1.2.0-final
stable version 1.2.0 brings feature parity with vaadin-spring

Guice Vaadin integration version 1.3.0
feature parity with spring and some bugfixes

Guice Vaadin integration version 1.3.1
fix for possible race-condition, which can occur in rare cases with many concurrent users

Guice Vaadin integration version 1.3.2
null

Guice Vaadin integration version 1.3.3
updated dependencies to reflections and mockito

Guice Vaadin integration version 1.3.3-vaadin8
compiled version 1.3.3-vaadin8 for use with Vaadin 8

Guice Vaadin integration version 1.3.4
better javadoc

Guice Vaadin integration version 1.4.0-vaadin8
support for VaadinServiceInitListener, better javadoc

Guice Vaadin integration version 2.0.0-alpha1
null

Guice Vaadin integration version 2.0.0-alpha2
null

Guice Vaadin integration version 2.0.0-beta1
null

Guice Vaadin integration version 2.0.0-beta2
removed @GuiceUI#errorViewProvider, fix for GuiceUI#errorView

Guice Vaadin integration version 2.0.0-beta4
bring back @ViewScope and introduces @Controller

Guice Vaadin integration version 2.0.0-beta5
fix for GuiceViewProvider

Guice Vaadin integration version 2.0.0-FINAL

Guice Vaadin integration version 2.0.1-vaadin8
possible NPE fix

Guice Vaadin integration version 2.0.1-vaadin10
Vaadin 10, finally. ViewScope and @Controller-annotation had been removed, no other major changes.

Guice Vaadin integration version 2.1.0-vaadin10
I18NProvider is now created by guice

Guice Vaadin integration version 2.3.0-vaadin10

Guice Vaadin integration version 2.3.1-vaadin10
dependency updates

Guice Vaadin integration version 2.3.3-vaadin10

Guice Vaadin integration version 2.3.4-vaadin10

Guice Vaadin integration version 2.3.6-vaadin10
some smaller memory-improvements

Guice Vaadin integration version 2019.1-vaadin14
Vaadin14 release with minimized dependencies, fixed tests and dependency updates

Guice Vaadin integration version 2020.1-vaadin14
cut out some dependencies

Online