vaadin应用程序的开发类似于桌面应用的开发。
5分钟教程:
首先要有一个主程序入口(继承com.Vaadin.Application),实现init方法(类似main方法)
代码示例:
import com.Vaadin.Application; import com.Vaadin.ui.*; public class Dw_Vaadin_projectApplication extends com.Vaadin.Application { public void init() { /*... 创建主窗口 ...*/ Window main = new Window("Dw_Vaadin_project Application");
/*... 设定主窗口 ...*/
setMainWindow(main); /*... 在主窗口中添加其他 UI 组件 ...*/ Label label=new Label("Hello Vaadin user"); main.addComponent(label); Window window = new Window("Sub Window"); main.addWindow(Window); } }
以下为效果图:
1小时教程:
以下以SpringRoo 的Pizzashop代码为例:
Pizzashop创建请遵照此篇wiz
1.Pizzashop应用入口类:
public class PizzaShopApplication extends Application {
@Override
public void init() {
Window window = createNewWindow();
setMainWindow(window);
}
/*... 创建一个单例的Window对象,并注册关闭事件避免内存泄露 ...*/
public Window createNewWindow() {
final Window window = new PizzaShopWindow();
// remove window on close to avoid memory leaks
window.addListener(new CloseListener() {
public void windowClose(CloseEvent e) {
if (getMainWindow() != window) {
PizzaShopApplication.this.removeWindow(window);
}
}
});
return window;
}
@Override
public Window getWindow(String name) {
// See if the window already exists in the application
Window window = super.getWindow(name);
// If a dynamically created window is requested, but
// it does not exist yet, create it.
if (window == null) {
// Create the window object.
window = createNewWindow();
window.setName(name);
// Add it to the application as a regular
// application-level window
addWindow(window);
}
return window;
}
2.vaadin基础知识
vaadin采用组件式开发。一切都是围绕控件的。
重要概念:
component 组件
navigator,导航 通过导航类实现页面切换,跳转
event & listener 事件与监听器
container,item,properties vaadin的数据抽象
详细介绍:
component 是组件基类,组件可以注册事件。vaadin提供很多组件,组件有自己特征的属性,还有通用属性