如何在我的网页中嵌入在Visual编辑器中创建的Vaadin Composite组件?

时间:2015-04-13 08:58:20

标签: java eclipse vaadin

我正在尝试为我的网站设计一个网页。我正在使用Vaadin框架和Java语言。我在Vaadin中使用Visual编辑器来放置UI元素,即我创建了一个复合组件。这是在MyComponent.java类中完成的。我有一个DownloadManager.java类,它扩展了UI类并显示了网页。我尝试在UI类中创建MyComponent.java的对象,以便我使用可视化编辑器添加的所有组件都显示在网页上。但这样做并不能显示除空白页面之外的任何内容。 如果问题非常简单,那么我很擅长使用Vaadin Framework这么好的借口。我遵循了Book of Vaadin的指导原则,但找不到上述问题的答案。 以下是我的课程的代码片段:

public class DownloadmanagerUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = DownloadmanagerUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        //final VerticalLayout layout = new VerticalLayout();
        //layout.setMargin(true);
        //setContent(layout);
        MyComponent m = new MyComponent();
        //layout.addComponent(m);
        /*Button button = new Button("Click Me");
        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {

                layout.addComponent(new Label("Thank  for clicking"));
            }
        });
        layout.addComponent(button);*/

    }

Mycomponent.java:

public class MyComponent extends CustomComponent {

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    @AutoGenerated
    private AbsoluteLayout mainLayout;
    @AutoGenerated
    private TextField textField_2;
    @AutoGenerated
    private TextField textField_1;
    @AutoGenerated
    private LoginForm loginForm_1;
    @AutoGenerated
    private Label label_1;
    @AutoGenerated
    private Button button_1;
    /**
     * The constructor should first build the main layout, set the
     * composition root and then do any custom initialization.
     *
     * The constructor will not be automatically regenerated by the
     * visual editor.
     */
    public MyComponent() {
        buildMainLayout();
        setCompositionRoot(mainLayout);

        // TODO add user code here
    }

    @AutoGenerated
    private AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setImmediate(false);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("100%");

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // button_1
        button_1 = new Button();
        button_1.setCaption("Button");
        button_1.setImmediate(true);
        button_1.setWidth("-1px");
        button_1.setHeight("-1px");
        mainLayout.addComponent(button_1, "top:314.0px;left:200.0px;");

        // label_1
        label_1 = new Label();
        label_1.setImmediate(false);
        label_1.setWidth("-1px");
        label_1.setHeight("-1px");
        label_1.setValue("Label");
        mainLayout.addComponent(label_1, "top:82.0px;left:131.0px;");

1 个答案:

答案 0 :(得分:2)