vaadin generated page doesnt show any component(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后,浏览器上不显示任何内容。
推荐答案
好的,您调用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();
应
- 在"类MyFirstApp"中声明并初始化
- 通过addComponent()添加到布局
详细布局(和其他基础知识)也在Vaadin书中介绍:
瓦丁之书:https://vaadin.com/book/-/page/intro.html
瓦丁之书-布局:Layout:https://vaadin.com/book/-/page/layout.html
Vaadin布局示例:http://demo.vaadin.com/sampler#Layouts
这篇关于VaAdin生成的页面不显示任何组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:VaAdin生成的页面不显示任何组件
基础教程推荐
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01