0

when I run this code I go this error

No active contexts for scope type javax.enterprise.context.RequestScoped

any help please , what should I do? I'm using this code to do chatting between different user so I'm the servlet bean extract different connected user

import javax.enterprise.context.RequestScoped;

@RequestScoped
@Named
public class ServletBean implements Serializable{


    private static final long serialVersionUID = 1L;
    /**
     * 
     */
    @Inject
    CompanyController  companyController;
    @Inject
    CandidateController candidateController;
    private int id;
    private int idCandidate;
    @PostConstruct
    public void display(){
        ELContext elContext = FacesContext.getCurrentInstance()
                .getELContext();
        companyController = (CompanyController) FacesContext
                .getCurrentInstance().getApplication().getELResolver()
                .getValue(elContext, null, "companyController");
        ELContext elContext1 = FacesContext.getCurrentInstance()
                .getELContext();
        candidateController = (CandidateController) FacesContext
                .getCurrentInstance().getApplication().getELResolver()
                .getValue(elContext1, null, "candidateController");
        if (companyController.getIdCompany()!= 0) {
            id=companyController.getIdCompany();
        }
        if (candidateController.getConnectedCandidate().getIdUserInformation()!=0) {
            id = candidateController.getConnectedCandidate().getIdUserInformation();
        }


        System.out.println("ligne 11+id1"+id+idCandidate);
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getIdCandidate() {
        return idCandidate;
    }
    public void setIdCandidate(int idCandidate) {
        this.idCandidate = idCandidate;
    }
}

@ServerEndpoint(value = "/websocket/{client-id}")
public class MyServerEndpoint {

    private static final LinkedList<Session> clients = new LinkedList<Session>();
    @Inject
    ServletBean servletBean;
    @Inject
    ChatlogBean chatlogBean;
    ChatLog chatLog;

    @OnOpen
    public void onOpen(Session session) {
    System.out.println("ligne 26"+  session.getUserPrincipal()+"*******"+session.getId());

    clients.add(session);
    }

    @OnMessage
    public void onMessage(String message,
            @PathParam("client-id") String clientId) {
        for (Session client : clients) {
            try {
                client.getBasicRemote().sendObject(clientId + ": " + message);
                System.out.println("ligne 26 message" + message + "clientId"
                        + clientId);
                System.out.println("ligne 57"+servletBean.getId());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (EncodeException e) {
                e.printStackTrace();
            }
        }
    }

    @OnClose
    public void onClose(Session peer) {
        clients.remove(peer);
    }

}
Geinmachi
  • 1,251
  • 1
  • 8
  • 20
steve.vai
  • 49
  • 1
  • 6

0 Answers0