FacesContext facesContext = FacesContext.getCurrentInstance(); Application application = facesContext.getApplication(); String version = application.getVersion(); System.out.println("Application version: " + version);
FacesContext facesContext = FacesContext.getCurrentInstance(); Application application = facesContext.getApplication(); MyBean myBean = (MyBean) application.evaluateExpressionGet( facesContext, "#{myBean}", MyBean.class);This code obtains an instance of a managed bean named "myBean" using the getApplication() method of FacesContext. The evaluateExpressionGet() method of Application is used to evaluate an EL expression that identifies the bean by its name. The type of the bean is specified using the third parameter of evaluateExpressionGet(), which allows for type-safe casting of the returned object. The javax.faces package library contains the FacesContext class and the other classes and interfaces that make up the JavaServer Faces API.