我正嘗試構建一個簡單的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中
請參閱http://stackoverflow.com/q/11988415/1065197以更好地管理您的資源文件(CSS,JS等)。 –
除了模板文件在公開以及模板文件中不必要的doctype/html聲明之外,我沒有看到任何奇怪的事情。您是否使用自定義資源處理程序?無論如何,在Mojarra的'ResourceHandlerImpl#createResource()'上放一個斷點並從那裏前進。 – BalusC
@LuiggiMendoza感謝您對使用「庫」屬性的預期方式的建議。 – kftse