0

I have jsp page inside which am calling my xhtml page. Am mapping xhtml to facesServlet and have all resource servlet active so it maps all js and css file fine, if i hit xhtml page.

If I hit jsp page then those files are not referenced firebug pops out all sorts of js errors.

To work around, i added js and css files to web folder and am including and tried them including in xhtml as well as jsp page but those are not referenced and as of now, if i directly hit xhmtl page then file upload works fine but if i go and hit jsp page then end up getting js errors, is there any other way of getting js file included.

Here is how am referencing my js files

<%@ include file="/common/taglibs.inc" %>

<html>
<head>
    <link rel="stylesheet" href="/css/Main.css" type="text/css">
    <link rel="stylesheet" href="/css/Admin.css" type="text/css">
    <link rel="stylesheet" href="/css/Home.css" type="text/css">
    <script type="text/javascript" src="/js/icefaces/ace-jquery.js"/>
    <script type="text/javascript" src="/js/icefaces/ace-components.js"/>
    <script type="text/javascript" src="/js/icefaces/icepush.js"/>
    <script type="text/javascript" src="/js/icefaces/bridge.js"/>
    <script type="text/javascript" src="/js/icefaces/compat.js"/>
    <script type="text/javascript" src="/js/icefaces/fileEntry.js"/>
    <script type="text/javascript" src="/js/icefaces/jsf.js"/>
    <script type="text/javascript" src="/js/icefaces/icefaces-compat.js"/>


    <!-- BEGIN SCRIPT TO OPEN RIGHT NOW HELP POPUP, THIS SCRIPT INCLUDES THE FUNCTION OPENRN-->
    <
    %@ include file="/js/popupRightNow.inc" %>

    <!-- END SCRIPT TO OPEN RIGHT NOW HELP POPUP, THIS SCRIPT INCLUDES THE FUNCTION OPENRN-->

    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<jsp:include page="/navigation/TopNav.jsp" flush="true"/>

<jsp:include page="/trade_entry/UploadBlotter.xhtml"/>


<!--BEGIN BOTTOM NAV -->
<jsp:include page="/navigation/BottomNav.jsp" flush="true"/>
<!--END BOTTOM NAV -->
</body>
</html>

Any thoughts, suggestions?

Update:

I have requirement of creating new pages using jsf2 and i have created xhtml page but i want to get my application header and footer themes and those are defined in jsp now I tried looking for integrating jsp into xhtml but it was rightly suggested that one must not do it.

Tried How to include a JSP page in a Facelets page? but that didn't work either as my tags were not recognized and so finally tried creating jsp page and included xhtml page inside it and that seemed to work but not 100%.

So as it stands right now if i hit xhtml page directly then it works but if i hit jsp page with header/footer information then icefaces or say jsf stuffs doesn't work 100%, hope am able to clarify what am trying to achieve.

Update 2

js file from javax.faces.resources are referenced fine on xhtml page but are not referenced on jsp page.

Community
  • 1
  • 1
Rachel
  • 100,387
  • 116
  • 269
  • 365

1 Answers1

2

It's the webbrowser who has got to download those JS/CSS files. It's not the server who has got to load/include those JS/CSS files.

So, the path which you specified in src and href attributes are resolved relative to the current request URL as you see in browser's address bar. They are not resolved relative to the location of the JSP file in the public webcontent.

So, if you happen to have a context path in the request URL like so

http://localhost:8080/somecontextpath/page.jsp

then for example your <link href="/css/Main.css"> would be downloaded by the webbrowser from the following URL

http://localhost:8080/css/Main.css

while it should actually have been

http://localhost:8080/somecontextpath/css/Main.css

Fix it accordingly.

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/Main.css" type="text/css">

Or if you're using Facelets

<link rel="stylesheet" href="#{request.contextPath}/css/Main.css" type="text/css">

Or if you're using JSF 2 <h:outputStylesheet> (and <h:outputScript> components)

<h:outputStylesheet name="css/Main.css" />

(and put the /css and /js folders in /resources subfolder of public webcontent)


By the way, the following line makes absolutely no sense:

<jsp:include page="/trade_entry/UploadBlotter.xhtml"/>

You're mixing view technologies here. You can't include the one in the other. Facelets is the successor of JSP. Use the one or the other. You can mix them in 1 webapp, but not in 1 view.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have updated my question with more detail and use case scenario for using jsp and xhtml page together. – Rachel Apr 12 '12 at 14:35
  • This is offtopic. This has completely nothing to do with problems with referencing JS/CSS files. Ask a new question. – BalusC Apr 12 '12 at 14:36