What is the best way to enable my webapplication to use JSF files stored in the database?
I’d like to be able to dynamically (during runtime) create new JSF pages which will be made available without having to redeploy the application.
So in other words: I would like to store the bigger part of my JSF pages in the database and would like JSF to use the database as a datasource for getting JSF files.
I’ve thought long about a solution and found some possible ways. However, I haven’t been able to implement either of them.
- Whenever a new page has to be added/removed: manipulate the files in the classpath (e.g. remove or add a file to the .war file)
- Extending the classpath of the webapplication so it will be able to get files from an at runtime defined location (i.e. /tmp or directly using a database connection)
- Provide JSF with a way to find resources another way ( this doesn’t seem possible? )
My environment:
- Java SE 6
- Jetty as servlet container
- Mojarra as jsf implementation
Now, my question:
Is it possible for someone to let JSF find pages at a location other than the default classpath, preferably the database?
Any response is greatly appreciated!
This is definitely possible if the WAR is expanded. I am not sure about Jetty, but it works for me with Mojarra 2.x on Tomcat 7 and Glassfish 3. Just writing the file to the expanded WAR folder the usual Java IO way suffices.
This needs to be executed before the
FacesServletkicks in. AFilteris a perfect place. See also this related answer:You can package Facelets files in a JAR file and put it in the classpath and provide a Facelets
ResourceResolverwhich serves the files from the JAR on when no match is found in WAR. You can find complete code examples in the following answers:You’ve plenty of play room in the custom
ResourceResolver.