2014-09-12 63 views
0

我使用Vaadin创建一个新的登录表单。我有两个类,如下所示:在Vaadin中登录表单

LoginUI.java是引入包含Login页面代码的LoginView.java的基类。它仍然是一个原型,并没有实现听众。但是,当我在tomcat上部署和运行时,我看到没有显示任何事件的空白页面。有人可以帮忙吗?

LoginUI.java - 基类

public class LoginUI extends UI { 

@WebServlet(value = "/*", asyncSupported = true) 
@VaadinServletConfiguration(productionMode = false, ui = LoginUI.class) 
public static class Servlet extends VaadinServlet { 
} 

@Override 
protected void init(VaadinRequest request) { 
    LoginView view = new LoginView(); 
    setContent(view); 
} 
} 

LoginView.java

public class LoginView extends VerticalLayout implements ClickListener {

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 

private final Label feedback; 

private final TextField username; 
private final TextField password; 

private final Button registerBtn; 
private final Button loginBtn; 
private HorizontalLayout layout= new HorizontalLayout(); 

public LoginView() { 

    feedback = new Label(); 
    layout.addComponent(feedback); 

    username = new TextField("Username"); 
    username.setWidth("100%"); 
    username.setNullRepresentation(""); 
    layout.addComponent(username); 

    password = new TextField("Password"); 
    password.setWidth("100%"); 
    password.setNullRepresentation(""); 
    layout.addComponent(password); 

    loginBtn = new Button("Sign In"); 
    layout.addComponent(loginBtn); 

    registerBtn = new Button("Register"); 
    layout.addComponent(registerBtn); 
    setSizeFull(); 
} 


public void buttonClick(ClickEvent event) { 
    if (event.getButton().equals(loginBtn)) { 
     String username = (String) this.username.getValue(); 
     String password = (String) this.password.getValue(); 
     Notification.show("User Present"); 
    } 
} 

}

回答

0

你LoginView是它VerticalLayout和您使用的是HorizontalLayout和添加所有你的组件。但你永远不会在HorizontalLayout(布局)到VerticalLayout。所以,醚添加广告这样说:

addCompontent(layout); 

但我不明白为什么LoginView是VerticalLayout。 或不要用户HorizontalLayout

public LoginView() { 

    feedback = new Label(); 
    addComponent(feedback); 

    username = new TextField("Username"); 
    username.setWidth("100%"); 
    username.setNullRepresentation(""); 
    addComponent(username); 

    password = new TextField("Password"); 
    password.setWidth("100%"); 
    password.setNullRepresentation(""); 
    addComponent(password); 

    loginBtn = new Button("Sign In"); 
    addComponent(loginBtn); 

    registerBtn = new Button("Register"); 
    addComponent(registerBtn); 
    setSizeFull(); 
}