我正在尝试为我的网站设计一个网页。我正在使用Vaadin框架和Java语言。我在Vaadin中使用了可视化编辑器来放置UI元素,即创建了一个复合组件。这是在类MyComponent.java中完成的。我有一个DownloadManager.java类,它扩展了UI类并显示了网页。我尝试在UI类中创建MyComponent.java对象,以便将使用可视化编辑器添加的所有组件显示在网页上。但是这样做只会显示空白页。
我对使用Vaadin Framework非常陌生,因此如果问题很琐碎,请您原谅。我也遵循了《瓦丹经书》的指导方针,但是找不到上述问题的答案。
以下是我的课程的代码段:

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;");

最佳答案

在您的init呼叫中:setContent(m)https://vaadin.com/api/7.4.3/com/vaadin/ui/UI.html#setContent%28com.vaadin.ui.Component%29

关于java - 如何在我的网页中嵌入在Visual Editor中创建的Vaadin Composite组件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29601450/

10-13 03:09