1

我正在使用 Vaadin 框架,我必须实现 VaadinCDIServlet 才能在前端使用 @EJb 注释。当使用 VaadinCDIServlet 我的应用程序给我这个错误:

[错误] SRVE9990E:be.iris.navigator.MynavigatorUI$Servlet 类具有@WebServlet 注释,但未实现 javax.servlet.http.HttpServlet 接口。

我尝试用 VaadinServlet 替换 VaadinCDIServlet,前端工作正常,我没有收到任何错误,但我无法进行 EJB 注入,而是出现空指针异常。

package be.iris.navigator;
import javax.ejb.EJB;
import javax.inject.Inject;
//http://kushalbaldev.blogspot.com/2017/01/navigation-in-vaadin.html
import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.CDIViewProvider;
import com.vaadin.cdi.server.VaadinCDIServlet;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.Navigator.ComponentContainerViewDisplay;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

import be.iris.controllers.PersonInroRetrieveRemote;
import be.iris.views.ActivityView;
import be.iris.views.EmployeeManagementView;
import be.iris.views.Login;
import be.iris.views.MainView;

// This class is used as navigator, i'm making a one page application.
@SuppressWarnings("serial")
@CDIUI("")
public class MynavigatorUI extends UI{

    @EJB
    private PersonInroRetrieveRemote pr;
    @Inject
    CDIViewProvider viewProvider;
    public Navigator navigator;
    public static final String MAINVIEW = "main";
    public static final String EMPMAN = "help";
    public static final String Activity = "act";

    @Override
    protected void init(VaadinRequest request) {

        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);
        ComponentContainerViewDisplay viewDisplay = new ComponentContainerViewDisplay(layout);
        navigator = new Navigator(UI.getCurrent(), viewDisplay);
        navigator.addProvider(viewProvider);
        navigator.addView("", new Login());
        navigator.addView(MAINVIEW, new MainView());
        navigator.addView(EMPMAN, new EmployeeManagementView());
        navigator.addView(Activity, new ActivityView());

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


}

package be.iris.views;

import javax.ejb.EJB;
import javax.inject.Inject;

import com.vaadin.cdi.CDIUI;
import com.vaadin.cdi.CDIView;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

import be.iris.controllers.LoginControllerRemote;
import be.iris.controllers.PersonInroRetrieveRemote;
import be.iris.eventhandling.LoginControllerEvent;
import be.iris.eventhandling.NotifEvent;
import be.iris.navigator.MynavigatorUI;

// this pafe is the login view that i'm using for MyNavigatorUI.java
@CDIView("")
public class Login extends VerticalLayout implements View, LoginControllerEvent {

    @EJB
    private PersonInroRetrieveRemote pr;
    @EJB
    private LoginControllerRemote lcr;
    private TextField username;

    @Inject
    public Login() {
        setSizeFull();
        setSpacing(true);
        Label label = new Label("Enter your information below to log in.");
        username = new TextField("username");
        TextField password = new TextField("password");
        addComponent(label);
        addComponent(username);
        addComponent(password);
        addComponent(loginButton());
        addComponent(actBt());

    }

    @Override
    public void enter(ViewChangeEvent event) {

    }

    private Button loginButton() {
        Button button = new Button("Log In", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getUI().getNavigator().navigateTo(MynavigatorUI.MAINVIEW);

            }
        });
        return button;

    }

    private Button actBt() {
        Button button = new Button("ActivTESTTEST", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getUI().getNavigator().navigateTo(MynavigatorUI.Activity);

            }
        });
        return button;

    }

    @Override
    public void loginFailedTooOften(NotifEvent ne) {
        // TODO Auto-generated method stub

    }

}

我希望登录可以使用 CDI 以及我做错了什么。我是VAADIN的新手,请帮助我。

4

0 回答 0