我已经创建了vaadin demo来在屏幕上显示一个按钮,但它没有显示任何东西,希望你帮我解决这个问题,
我的申请:
public class StudentApplication extends Application {
private static final long serialVersionUID = 1L;
@Override
public void init() {
setTheme("mythemse");
final Window w = new Window();
setMainWindow(w);
setContent(new LoginView());
}
public void setContent(LoginView loginView) {
final Window window = new Window();
window.setCaption("Login");
window.setContent(loginView);
}
}
我的观点:
public class LoginView extends Panel {
private static final long serialVersionUID = 1L;
private final CustomLayout loginLayout = new CustomLayout("login");
public LoginView(){
initalize();
this.setSizeFull();
}
public void initalize() {
Button loginButton = new Button("TEST");
loginLayout.addComponent(loginButton,"testlogin");
this.setContent(loginLayout);
}
}
我的HTML:webapp / VAADIN / themses / mythemses / layouts / login.html
<body class="login">
<h1>
<div location="testlogin" style="padding-left: 100px;"></div>
</h1>
</body>
这是我的WEB-INF / web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Student</display-name>
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>vaadin.terminal.gwt</servlet-name>
<servlet-class>vaadin.servlet.VaadinApplicationServlet</servlet-class>
<init-param>
<description>Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>student.page.application.StudentApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>vaadin.terminal.gwt</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
我的servlet:
public class VaadinApplicationServlet extends ApplicationServlet {
private static final long serialVersionUID = 1L;
}
答案 0 :(得分:0)
在setContent()方法中,您创建了一个未添加到任何位置的新窗口,因此永远不会显示。 您需要将其设置为主窗口或将新的LoginView实例添加到主窗口。 即 或者这个,
public class StudentApplication extends Application {
private static final long serialVersionUID = 1L;
@Override
public void init() {
setTheme("mythemse");
//final Window w = new Window();
//setMainWindow(w);
setContent(new LoginView());
}
public void setContent(LoginView loginView) {
final Window window = new Window();
window.setCaption("Login");
window.setContent(loginView);
setMainWindow(window);
}
}
或者,
public class StudentApplication extends Application {
private static final long serialVersionUID = 1L;
@Override
public void init() {
setTheme("mythemse");
final Window w = new Window();
setMainWindow(w);
setContent(new LoginView(),w);
}
public void setContent(LoginView loginView, Window window) {
// final Window window = new Window();
window.setCaption("Login");
window.setContent(loginView);
}
}