Vaadin登录页面问题

Vaadin登录页面问题,vaadin,vaadin7,Vaadin,Vaadin7,我是Vaadin UI开发新手,如果有任何愚蠢的错误,请原谅。有人能帮忙吗 我正试图建立一个登录页面使用的链接中提到的瓦丁网站。但是我得到一个错误-com.vaadin.server.ServiceException:java.lang.RuntimeException:java.lang.InstanceionException 有三节课 1) 用于登录视图 2) 主视图 3) 在上述两个视图之间导航的主类 1) 登录视图如下所示: 公共抽象类SimpleLoginView扩展了Custom

我是Vaadin UI开发新手,如果有任何愚蠢的错误,请原谅。有人能帮忙吗

我正试图建立一个登录页面使用的链接中提到的瓦丁网站。但是我得到一个错误-com.vaadin.server.ServiceException:java.lang.RuntimeException:java.lang.InstanceionException

有三节课

1) 用于登录视图 2) 主视图 3) 在上述两个视图之间导航的主类

1) 登录视图如下所示:


公共抽象类SimpleLoginView扩展了CustomComponent实现视图,
Button.ClickListener{

private static final long serialVersionUID = 1L;

public static final String NAME = "login";

private final TextField user;

private final PasswordField password;

private final Button loginButton;

public SimpleLoginView() {
    setSizeFull();

    // Create the user input field
    user = new TextField("User:");
    user.setWidth("300px");
    user.setRequired(true);
    user.setInputPrompt("Your username (eg. joe@email.com)");
    user.addValidator(new EmailValidator(
            "Username must be an email address"));
    user.setInvalidAllowed(false);

    // Create the password input field
    password = new PasswordField("Password:");
    password.setWidth("300px");
    password.addValidator(new PasswordValidator());
    password.setRequired(true);
    password.setValue("");
    password.setNullRepresentation("");

    // Create login button
    loginButton = new Button("Login", this);

    // Add both to a panel
    VerticalLayout fields = new VerticalLayout(user, password, loginButton);
    fields.setCaption("Please login to access the application. (test@test.com/passw0rd)");
    fields.setSpacing(true);
    fields.setMargin(new MarginInfo(true, true, true, false));
    fields.setSizeUndefined();

    // The view root layout
    VerticalLayout viewLayout = new VerticalLayout(fields);
    viewLayout.setSizeFull();
    viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
    viewLayout.setStyleName(Reindeer.LAYOUT_BLUE);
    setCompositionRoot(viewLayout);
}

@Override
public void enter(ViewChangeEvent event) {
    // focus the username field when user arrives to the login view
    user.focus();
}

// Validator for validating the passwords
private static final class PasswordValidator extends
AbstractValidator<String> {

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

    public PasswordValidator() {
        super("The password provided is not valid");
    }

    @Override
    protected boolean isValidValue(String value) {
        //
        // Password must be at least 8 characters long and contain at least
        // one number
        //
        if (value != null
                && (value.length() < 8 || !value.matches(".*\\d.*"))) {
            return false;
        }
        return true;
    }

    @Override
    public Class<String> getType() {
        return String.class;
    }
}

@Override
public void buttonClick(ClickEvent event) {

    //
    // Validate the fields using the navigator. By using validors for the
    // fields we reduce the amount of queries we have to use to the database
    // for wrongly entered passwords
    //
    if (!user.isValid() || !password.isValid()) {
        return;
    }

    String username = user.getValue();
    String password = this.password.getValue();

    //
    // Validate username and password with database here. For examples sake
    // I use a dummy username and password.
    //
    boolean isValid = username.equals("test@test.com")
            && password.equals("passw0rd");

    if (isValid) {

        // Store the current user in the service session
        getSession().setAttribute("user", username);

        // Navigate to main view
        getUI().getNavigator().navigateTo(MainView.NAME);//

    } else {

        // Wrong password clear the password field and refocuses it
        this.password.setValue(null);
        this.password.focus();

    }
}
}

3) 在上述两个视图之间导航的主类


公共类LoginUI扩展用户界面{

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

@Override
protected void init(VaadinRequest request) {

    //
    // Create a new instance of the navigator. The navigator will attach
    // itself automatically to this view.
    //
    new Navigator(this, this);

    //
    // The initial log view where the user can login to the application
    //
    getNavigator().addView(SimpleLoginView.NAME, SimpleLoginView.class);//

    //
    // Add the main view of the application
    //
    getNavigator().addView(MainView.NAME,
            MainView.class);

    //
    // We use a view change handler to ensure the user is always redirected
    // to the login view if the user is not logged in.
    //
    getNavigator().addViewChangeListener(new ViewChangeListener() {

        @Override
        public boolean beforeViewChange(ViewChangeEvent event) {

            // Check if a user has logged in
            boolean isLoggedIn = getSession().getAttribute("user") != null;
            boolean isLoginView = event.getNewView() instanceof SimpleLoginView;

            if (!isLoggedIn && !isLoginView) {
                // Redirect to login view always if a user has not yet
                // logged in
                getNavigator().navigateTo(SimpleLoginView.NAME);
                return false;

            } else if (isLoggedIn && isLoginView) {
                // If someone tries to access to login view while logged in,
                // then cancel
                return false;
            }

            return true;
        }

        @Override
        public void afterViewChange(ViewChangeEvent event) {

        }
    });
}
}

在Tomcat中运行代码时,出现以下错误:

`
类型异常报告

message com.vaadin.server.ServiceException: java.lang.RuntimeException:       java.lang.InstantiationException
说明服务器遇到内部错误,无法满足此请求。 例外情况

javax.servlet.ServletException:com.vaadin.server.ServiceException:java.lang.RuntimeException:java.lang.InstanceionException com.vaadin.server.VaadinServlet.service(VaadinServlet.java:307) javaservlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

com.vaadin.server.ServiceException:java.lang.RuntimeException:java.lang.InstanceionException com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1460) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1414) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) javaservlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

java.lang.RuntimeException:java.lang.InstanceionException navigator$ClassBasedViewProvider.getView(navigator.java:340) navigator.navigator.navigateTo(navigator.java:512) com.example.login.LoginUI$1.beforeViewChange(LoginUI.java:58) fireBeforeViewChange(navigator.java:595) com.vaadin.navigator.navigator.navigateTo(navigator.java:553) com.vaadin.navigator.navigator.navigateTo(navigator.java:526) com.vaadin.ui.ui.doInit(ui.java:644) com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) com.vaadin.server.communication.UIInitHandler.SynchronizedHandlerRequest(UIInitHandler.java:74) SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1402) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) javaservlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

java.lang.InstanceionException sun.reflect.InstanceExceptionConstructorAccessorImpl.newInstance(未知源) java.lang.reflect.Constructor.newInstance(未知源) java.lang.Class.newInstance(未知源) navigator$ClassBasedViewProvider.getView(navigator.java:336) navigator.navigator.navigateTo(navigator.java:512) com.example.login.LoginUI$1.beforeViewChange(LoginUI.java:58) fireBeforeViewChange(navigator.java:595) com.vaadin.navigator.navigator.navigateTo(navigator.java:553) com.vaadin.navigator.navigator.navigateTo(navigator.java:526) com.vaadin.ui.ui.doInit(ui.java:644) com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) com.vaadin.server.communication.UIInitHandler.SynchronizedHandlerRequest(UIInitHandler.java:74) SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1402) com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) javaservlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

注意,Apache Tomcat/7.0.55日志中提供了根本原因的完整堆栈跟踪



`

如果视图是通过
Navigator#addView(String viewName,class)添加到导航器中的,则Vaadin的Navigator类会尝试通过反射实例化其视图类。您应该重新格式化您的问题,以便能够正确阅读(驯鹿。蓝色布局);我认为这应该将背景颜色设置为蓝色,但目前没有。它没有任何背景颜色。请告诉我如何实现它?要更改Vaadin应用程序的外观和感觉,我建议您看看Vaadin主题:这是一个太广泛的主题,无法在评论中处理:)
message com.vaadin.server.ServiceException: java.lang.RuntimeException:       java.lang.InstantiationException