Search code examples
jsfmanaged-bean

Add ManagedBean to JSF context at runtime


I'm trying to create a plugin/componentFramework with Java for WebApplications. I'm using Tomcat9, JSF(2.1.13) and Java 1.8.

I have a .war File. When i deploy this .war file to Tomcat on startup a scheduler gets started and this scheduler will call every 15 seconds a method which observes a given (HotDeployment) Folder. If a jar or zip file gets deployed to that folder the file gets unzipped and the classes get loaded via a new ClassLoader.

Now i have a simple Plugin(SimplePlugin.jar) with one HelloWorld.class which has the Annotation @ManagedBean and @RequestScoped. How can i add or register this ManagedBean (when i have a Object of that class) dynamically/programmatically to the JSF Context at runtime? So when i call a .xhtml File that this class gets recognized.

I tried it with the FacesContext and I oriented myself at this answer: How to register a JSF managed bean programmatically? but i still cant figure out how to do it. How can i achieve this?


Solution

  • Thanks Kukeltje and SovietFrontier for your Answers. You were right the link i posted in my Question had the right answer. I had a typo...