0

我已经创建了 vaadin 演示来在屏幕上显示一个按钮,但它什么也没显示,希望你能帮助我解决这个问题,

我的应用程序 :

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>

我的小服务程序:

public class VaadinApplicationServlet extends ApplicationServlet {
    private static final long serialVersionUID = 1L;

}
4

1 回答 1

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);
        }
        }
于 2013-10-12T12:03:17.217 回答