Vaadin 7.x supports only.
Current version: Vaadin 7.0.0
http://vaadin.com/addon/springvaadinintegration
beanName - Spring bean name of root UI.
web.xml
<servlet>
<servlet-name>Test Application</servlet-name>
<servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
<init-param>
<param-name>beanName</param-name>
<param-value>myUI</param-value>
</init-param>
</servlet>
<!-- Bind as ordinary VaadingServlet -->
<servlet-mapping>
<servlet-name>Test Application</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Test Application</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
UI class example
@Component
@Scope("prototype")
@Theme("myTheme")
public class MyUI extends UI
{
private static Logger logger = LoggerFactory.getLogger(TrackerUI.class);
@Autowired
private transient ApplicationContext applicationContext;
@Autowired
private MyClass myClass;
....
}
New DiscoveryNavigator.
Using example:
@Component
@Scope("prototype")
@Theme("myTheme")
public class MyUI extends UI
{
@Autowired
private MyClass myClass;
@Override
protected void init(final VaadinRequest request)
{
DiscoveryNavigator navigator = new DiscoveryNavigator(this, this);
navigator.navigateTo(UI.getCurrent().getPage().getUriFragment());
}
}
View example:
@Component
@Scope("prototype")
@VaadinView(MainView.NAME)
public class MainView extends Panel implements View
{
public static final String NAME = "profile";
@Autowired
private transient ApplicationContext applicationContext;
@Autowired
private SimpleForm form;
@PostConstruct
public void PostConstruct()
{
MainLayout mainLayout = new MainLayout();
mainLayout.setContent(form);
setContent(mainLayout);
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event)
{
}
}
You can cache View in UI instance. It created only once for every UI instance.
See sample project.
@Component
@Scope("prototype")
@VaadinView(value = UIScopedView.NAME, cached = true)
public class UIScopedView extends Panel implements View
{
...
@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent)
{
...
}
}
pom.xml
...
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>ru.xpoft.vaadin</groupId>
<artifactId>spring-vaadin-integration</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
You should use "transient" attribute for ApplicationContext and other's context's beans.
@Autowired
private transient ApplicationContext applicationContext;
You can use Spring MessageSource as source for Vaadin SystemMessages. And wow! Now you can use localized messages!
You should reload page after changing language. Texts for CommunicationError and AuthenticationError implements on page loading. It's Vaadin.
web.xml
<servlet>
<servlet-name>Vaadin Application</servlet-name>
<servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
...
<init-param>
<param-name>systemMessagesBeanName</param-name>
<param-value>DEFAULT</param-value>
</init-param>
</servlet>
in your Spring messages:
vaadin.sessionExpired.Caption = ...
vaadin.sessionExpired.Message = ...
vaadin.sessionExpired.URL = ...
vaadin.sessionExpired.NotificationEnabled = ... (true / false)
Other message types: communicationError, authenticationError, internalError, outOfSync, cookiesDisabled
vaadin.communicationError.Caption = ...
If some translations don't found, it will use default Vaadin message. So you can translate "caption" only, for example.
web.xml
<servlet>
<servlet-name>Vaadin Application</servlet-name>
<servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
...
<init-param>
<param-name>systemMessagesBeanName</param-name>
<param-value>customSystemMessages</param-value>
</init-param>
</servlet>
CustomSystemMessages class must implements SpringSystemMessagesProvider interface.
Use ShiroSecurityNavigator instead of DiscoveryNavigator. ShiroSecurityNavigator user @RequiresRoles and @RequiresPermissions of View class. If user doesn't have permission, View is not visible.
See sample project
ShiroSecurityNavigator navigator = new ShiroSecurityNavigator(this, getContent());
navigator.navigateTo(UI.getCurrent().getPage().getFragment());
@Component
@Scope("prototype")
@VaadinView(RoleUserView.NAME)
@RequiresRoles("user")
public class RoleUserView extends Panel implements View
{
public static final String NAME = "role_user";
...
}
https://github.com/xpoft/vaadin-samples#spring-vaadin-integration
git clone git://github.com/xpoft/spring-vaadin.git -b sample spring-vaadin
cd spring-vaadin
mvn jetty:run
Then go to http://locahost:9090
Simple library. Vaadin 7.0+ not supported. Last update: Apr 26, 2011
Simple library. Vaadin 7.0+ not supported. Last update: Sep 5, 2011
Vaadin 7.0+ not supported. Last update: Sep 14, 2010
Very good library. It was the best (and only one) library for integration with Spring. Vaadin 7.0+ supported. Last update: Aug 28, 2012
- Vaadin 7.0.0
- Vaadin 7.0.0.beta10 Vaadin changes. Now UI.getContent() return instance of Component. Replace: DiscoveryNavigator navigator = new DiscoveryNavigator(this, getContent()); With: DiscoveryNavigator navigator = new DiscoveryNavigator(this, this);
- Add @RequiresPermissions support
- Add Apache Shiro support. Simple check for roles.
- String VaadinView.scope renamed to boolean VaadinView.cached. Be careful.
- Vaadin 7.0.0.beta6
- replace AspectJ with static access to the application context. Now you can remove 'context:spring-configured/'
- add view scopes: prototype (default) and ui
- Vaadin 7.0.0.beta5
- Java 6.0 support
fix caching
- Simplify DiscoveryNavigator. It uses Spring Root Context to autowiring Vaadin Views, and AspectJ for non-managed classes.
- You should add 'context:spring-configured/' to your spring config. See sample project.
- Now serialization & deserialization work perfect.
- Vaadin 7.0.0.beta4 support
- Enhanced SystemMessages bean support. Now you can use localized messages! Simple & quick. See sample project.
- Use can use VaadinMessageSource, it's more simple way to use Spring MessageSource
- Add SystemMessages bean support. Now you can use Spring Beans as source for SystemMessages.
- Vaadin 7.0.0.beta3
- Improve DiscoveryNavigator (cache, performance). Now you should set "basePackage" in DiscoveryNavigator constuctor. Multi-jars, enhanced scanning already supported.
- Fix serialization.
- DiscoveryNavigator. Migrate from WebApplicationContext to ApplicationContext
- Add Vaadin 7.0.0.beta2 support
- Custom DescoveryNavigator
Default. Add all view-beans from root package:
DiscoveryNavigator navigator = new DiscoveryNavigator(applicationContext, UI.getCurrent().getPage().getCurrent(), display);
navigator.navigateTo(UI.getCurrent().getPage().getFragment());
Disable add view-beans to Navigator. You can do it manual.
DiscoveryNavigator navigator = new DiscoveryNavigator(applicationContext, UI.getCurrent().getPage().getCurrent(), display, false);
navigator.addBeanView("view1", MyView.class);
navigator.navigateTo(UI.getCurrent().getPage().getFragment());
or you can manual discover beans in a package
navigator.discoveryViews("ru.xpoft.vaadin.test");
you can exclude some packages
navigator.discoveryViews("ru.xpoft.vaadin.test", new String[] {"ru.xpoft.vaadin.test.one", "ru.xpoft.vaadin.test.two"})
- Autowiring UI
- DiscoveryNavigator