1: 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)
如果扩展WAR,这肯定是可能的.我不确定Jetty,但它适用于Tomcat 7和Glassfish 3上的Mojarra 2.x.只需将文件写入扩展的WAR文件夹,通常的Java IO方式就足够了.
File file = new File(servletContext.getRealPath("/foo.xhtml"));
if (!file.exists()) {
OutputStream output = new FileOutputStream(file);
try {
output.write(bytes); // Can be bytes from DB.
} finally {
output.close();
}
}
这需要在FacesServlet启动之前执行.过滤器是一个完美的地方.另见相关答案:
2: 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)
您可以将Facelets文件打包到JAR文件中并将其放在类路径中,并提供Facelets ResourceResolver,当WAR中找不到匹配项时,它将提供来自JAR的文件.您可以在以下答案中找到完整的代码示例:
3: Provide JSF with a way to find resources another way ( this doesn’t seem possible? )
您在自定义ResourceResolver中有足够的游戏空间.