2013-07-12 45 views
0

我正尝试构建一个简单的JSF应用程序,但是当我在下面的代码中使用template/basic.xhtml添加css时,应用程序服务器(tomcat 7和glassfish 4)解析RES_NOT_FOUNDJSF/Facelets:找不到CSS文件资源

<h:head> 
    <title><ui:insert name="title">Enrollment System</ui:insert></title> 
    <h:outputStylesheet library="common" name="css/reset.css" /> 
    <h:outputStylesheet library="common" name="css/common.css" /> 
</h:head> 

的的index.xhtml包含简单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core"> 
<ui:composition template="/templates/basic.xhtml"> 
    <ui:define name="content"> 
     <h1>Welcome, #{loginSession.privilege}</h1> 
    </ui:define> 
</ui:composition> 
</html> 

我读过其他一些职位也Mkyong's JSF tutorial,我应该把CSS在一些特定的目录中,但仍然未能使其工作。

下面是在我的文件在放的位置:

enrollment/index.xhtml 
enrollment/WEB-INF/templates/basic.xhtml 
enrollment/resources/common/css/reset.css 
enrollment/resources/common/css/common.css 

是否有失踪使它工作的任何其他配置?

这是我在堆栈中找到的空ResourceInfo生成并返回。

Daemon Thread [http-bio-80-exec-3] (Suspended) 
owns: SocketWrapper<E> (id=62) 
ResourceManager.findResource(String, String, String, boolean, FacesContext) line: 190 
ResourceManager.findResource(String, String, String, FacesContext) line: 180  
ResourceHandlerImpl.createResource(String, String, String) line: 201  
ResourceHandlerImpl.createResource(String, String) line: 181  
StylesheetRenderer.encodeEnd(FacesContext, UIComponent) line: 97 

getFromCache将使用提供的四个参数在HashMap中进行搜索。

ResourceInfo info = getFromCache(resourceName, libraryName, localePrefix, contracts); 

我已经检查HashMap中所有的值,只有两种资源,即

"/" 
"/WEB-INF/templates/basic.xhtml" 

这可能是因为资源永远不会加入到HashMap中

+2

请参阅http://stackoverflow.com/q/11988415/1065197以更好地管理您的资源文件(CSS,JS等)。 –

+0

除了模板文件在公开以及模板文件中不必要的doctype/html声明之外,我没有看到任何奇怪的事情。您是否使用自定义资源处理程序?无论如何,在Mojarra的'ResourceHandlerImpl#createResource()'上放一个断点并从那里前进。 – BalusC

+0

@LuiggiMendoza感谢您对使用“库”属性的预期方式的建议。 – kftse

回答

0

我的事业解决了意外事故的问题。

修复程序在创建项目时不要选择“生成web.xml部署描述符”。

+1

这应该不会破坏事物。那么生成的'/ WEB-INF/web.xml'包含了什么? – BalusC

+0

一切都包含在内,面向servlet映射,过滤器,一些参数配置,但实际上我现在甚至不能重现RES_NOT_FOUND错误...可能是一些破坏的项目配置。 – kftse

+0

所以这不是这个问题的实际答案? – alexander