0

I am trying to build a simple JSF application, but when I add css in the template/basic.xhtml using the code below, application server (both tomcat 7 and glassfish 4) resolve to RES_NOT_FOUND

<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>

The index.xhtml contains simply

<!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>

I've read another few posts and also Mkyong's JSF tutorial that I should put css in some specific directory, but still failed to make it work.

Here are locations of where my files are put at:

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

Is there any other config that was missing to make it work?

Here is what I find in the stack which the null ResourceInfo is generated and returned.

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 will search in a HashMap using the four parameter provided.

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

I've examine all the values in the HashMap, there is only two resources namely

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

This probably is the cause as the resources are never added to the hashmap

kftse
  • 191
  • 2
  • 18
  • 2
    Refer to http://stackoverflow.com/q/11988415/1065197 for a better management of your resource files (CSS, JS, etc). – Luiggi Mendoza Jul 12 '13 at 23:25
  • Apart from the template file being in public and the unnecessary doctype/html declarations in the template file, I don't see any strange things. Are you using a custom resource handler? In any way, put a breakpoint on Mojarra's `ResourceHandlerImpl#createResource()` and advance from there. – BalusC Jul 13 '13 at 02:27
  • @LuiggiMendoza Thanks for your advice on the intended way to use "library" attribute. – kftse Jul 13 '13 at 09:28
  • @BalusC I have created a new dynamic web project with only a template, a css and index.xhtml containing no bean, but it does not work either, I am debuging on the newly created project. This seems not to be a project specific problem, does it matter if I use eclipse server plugins to auto publish the application? – kftse Jul 13 '13 at 09:32
  • Rightclick, export, WAR. Then unpack it with a ZIP tool. Are the files at the right place? – BalusC Jul 13 '13 at 13:04
  • @balusc They are in the right place, resources is in the same level as WEB-INF and index.xhtml – kftse Jul 13 '13 at 13:30

1 Answers1

0

I fixed the problem out of accident.

The fix is DO NOT select "Generate web.xml deployment descriptor" when creating project.

kftse
  • 191
  • 2
  • 18
  • 1
    That shouldn't break things. What did the generated `/WEB-INF/web.xml` contain then? – BalusC Jul 16 '13 at 11:56
  • Everything normally contained, faces servlet maping, filter, some parameter config, but actually I cannot even reproduce the RES_NOT_FOUND error now... Probably some broken project config. – kftse Jul 16 '13 at 23:34
  • So this is not an actual answer to this question? – alexander Mar 06 '15 at 15:08