If the instance of the mentioned class is running in the same thread as the HTTP request thread which has invoked the FacesServlet
, then you can just get it by the FacesContext
and then Application#evaluateExpressionGet()
. See also Get JSF managed bean by name in any Servlet related class
If the instance of the mentioned class is running in a different thread, then you'd need to pass the desired information beforehand to the class' constructor, method or to store the desired information in some shared datasource which both the JSF webapp and the standalone class have access to, such as a database, a local disk file system file or the JNDI context. Depending on the context and the environment, CDI's @Named
+@Inject
may also be the solution.
The "best way" depends on the concrete functional requirement which is not clear from the question, so I can't point out the right way nor give any kickoff examples.