我在哪里将我的应用程序的所有"胆量"放在Vaadin应用程序中?继续添加"MyUI"课程?

Bas*_*que 0 java layout vaadin vaadin7

我已经成功地启动并运行了我的第一个Vaadin 7应用程序,这是由Maven原型为我创建的.此应用程序的模板显示了窗口小部件的布局,窗口小部件和业务逻辑(单击按钮),所有这些都在MyUI类中定义.

我从哪里开始?我只是继续添加内容MyUI还是有更好的方法来构建我的应用程序?

这是MyUIMaven原型给我的Java源代码.

package com.example.vaadinlayoutsexample;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

/**
 * This UI is the application entry point. A UI may either represent a browser window 
 * (or tab) or some part of a html page where a Vaadin application is embedded.
 * <p>
 * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be 
 * overridden to add component to the user interface and initialize non-component functionality.
 */
@Theme("mytheme")
@Widgetset("com.example.vaadinlayoutsexample.MyAppWidgetset")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        final TextField name = new TextField();
        name.setCaption("Type your name here:");

        Button button = new Button("Click Me");
        button.addClickListener( e -> {
            layout.addComponent(new Label("Thanks " + name.getValue() 
                    + ", it works!"));
        });

        layout.addComponents(name, button);
        layout.setMargin(true);
        layout.setSpacing(true);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}
Run Code Online (Sandbox Code Playgroud)

app运行的屏幕截图.

在Web浏览器窗口中运行的Vaadin应用程序模板的屏幕截图

nyg*_*nyg 5

当你的应用程序开始有更多的视图时,你应该开始使用至少一个Navigator以及一个ViewProvider.这两个类都在Vaadin框架中.

Navigator对象将在MyUI类中创建.每个视图都实现了View界面,对于每个视图,您也可以拥有一个演示者(尽管这不是Vaadin概念).

定制ViewChangeListener以及定制NavigationStateManager也可能有用.

有关详细信息,请参阅https://vaadin.com/docs/-/part/framework/advanced/advanced-navigator.html.我也使用了"基础应用程序",它同时使用MVP和DAO模式,你可以在这里查看:https://github.com/nyg/vaadin-app-base.