本文介紹了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生成的頁面不顯示任何組件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,