JSF 2:How include style sheets and javascript?
i'm having a strange problem, if my page index.xhml is:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
//.. import css and javascript
</head>
<body>
// .. my page content
</body>
</html>
Everthing is okay, but, if i change to <head>
to <h:head>
and <body>
to </h:body>
my page it seems not apply the style very well, as far i can t开发者_StackOverflowell it seems my javascript file is not been applied in the page.
Why this happen ? I already try change to <h:outputScript library="javascript" name="file.js" />
but it doesn't work either.
Any idea ? Why this is happening ?
use this above body and then u can use the methods directly in your jsp
<script src="${pageContext.request.contextPath}/yourJSFile.js" type="text/javascript"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/yourCSSFile.css" type="text/css" />
yourJS.js yourCSS.css file should be under your WebContent(${pageContext.request.contextPath}) . Its better to maintain seperate folder for your js,css,pages etc.
精彩评论