vaadin生成的页面不显示任何组件

时间:2012-12-19 11:10:50

标签: java tomcat servlets vaadin

我在vaadin框架中遇到了一个问题。

我创建了一个类扩展vaadin应用程序(MyFirst),之后我用vaadin可视化设计器(MyFormApp)创建了一个自定义组件。

我确实实例化了自定义组件MyFormApp,并将其添加到MyFirst的主窗口中。

部署应用程序后,vaadin生成的页面不显示任何组件。

我的代码:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example.vaadin;

import com.vaadin.Application;
import com.vaadin.ui.*;

/**
*
* @author anis.bouchenafa
*/
public class MyFirst extends Application{


private Button newContact = new Button("Add contact");
private Button search = new Button("Search");
private Button share = new Button("Share");
private Button help = new Button("Help");
private HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
private TextField tf = new TextField();

@Override
public void init() {
    //buildMainLayout();

    MyFirstApp a = new MyFirstApp();
   Window w = new Window("aness conf");
   w.addComponent(a);
   setMainWindow(w);


}

}

我的第二堂课是MyFirstApp(自定义组件):

package com.example.vaadin;



import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.LoginForm;

public class MyFirstApp extends CustomComponent {

@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private LoginForm loginForm_2;

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



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

/**
 * 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 MyFirstApp() {
    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%");

    // loginForm_2
    loginForm_2 = new LoginForm();
    loginForm_2.setStyleName("v-loginform");
    loginForm_2.setImmediate(false);
    loginForm_2.setWidth("340px");
    loginForm_2.setHeight("-1px");
    mainLayout.addComponent(loginForm_2, "top:160.0px;left:200.0px;");

    return mainLayout;
}

}

执行servlet后,浏览器没有显示任何内容。

3 个答案:

答案 0 :(得分:2)

使用AbsoluteLayout,您需要定义组件的显示位置,例如:

mainLayout = new AbsoluteLayout();
mainLayout.setWidth("400px");
mainLayout.setHeight("350px");

有关详细信息,请参阅: https://vaadin.com/book/-/page/layout.absolutelayout.html

答案 1 :(得分:1)

好吧,你调用buildMainLayout()视觉上是空的。它只包含一个AbsoluteLayout和一个没有任何组件的LoginForm()。这就像生成无边框HTML表而不添加任何文本。

我认为您想添加的组件

private Button newContact = new Button("Add contact");
private Button search = new Button("Search");
private Button share = new Button("Share");
private Button help = new Button("Help");
private HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
private TextField tf = new TextField();

应该

  1. 在您的“MyFirstApp类”和
  2. 中声明并初始化
  3. 通过addComponent()
  4. 添加到您的布局中

    详细的布局(以及其他基础知识)也在Book of Vaadin中解释:

    Vaadin的书: https://vaadin.com/book/-/page/intro.html

    Vaadin书 - 布局:布局:https://vaadin.com/book/-/page/layout.html

    Vaadin布局示例: http://demo.vaadin.com/sampler#Layouts

答案 2 :(得分:0)

在Vaadin 7中使用Visual Editor时遇到了同样的问题。但是,如果从 AbsoluteLayout 布局 属性> 到任何其他布局(即GridLayout,Horizo​​ntalLayout或VerticalLayout)。该组件显示。希望有所帮助。