0

I have a JavaScript file stored in the web root like,

SocialNetworking/web/resources/js/decimal_number_text_field.js

I'm trying to import this js file in an XHTML page like,

<h:body>
    <ui:composition template="template/Template.xhtml">
        <ui:define name="content">

            <h:outputScript name="../resources/js/decimal_number_text_field.js"/>

        </ui:define>
    </ui:composition>
</h:body>

The path is correct but it doesn't work.


The generated JavaScript tag looks like the following.

<script type="text/javascript" src="/SocialNetworking/javax.faces.resource/../resources/js/decimal_number_text_field.js.jsf">
</script>

So, the src attribute contains a wrong URL. If this script is added to the template within the <h:head> tag like so,

<h:outputScript name="js/decimal_number_text_field.js"/>

then it works fine.

Why does it take a wrong URL when this tag is placed in an XHTML page which covers the template?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Tiny
  • 27,221
  • 105
  • 339
  • 599
  • Requires only `` that generates this URL - `/SocialNetworking/javax.faces.resource/js/decimal_number_text_field.js.jsf`. This works fine, sorry. – Tiny Jul 20 '13 at 19:53
  • I was writing you an answer. Do you understand what is going on or do you still want me to explain – Andy Jul 20 '13 at 19:54
  • Not sufficiently. Please add the answer :). – Tiny Jul 20 '13 at 19:56
  • I will see you tomorrow. It is about 2 AM. – Tiny Jul 20 '13 at 20:07
  • Sorry if I took so long to answer. I just knew this was answered already in SO. I just couldn't find it. So check the link below. – Andy Jul 20 '13 at 21:13

1 Answers1

-1

Try to use : #{request.contextPath} as below. Based one your file path, resources package must be under web application root directory.

or

<script type="text/javascript" src="#{request.contextPath}/resources/js/decimal_number_text_field.js.jsf">
</script>

directory structure :

applicaiton.war
     - resources
       - js
         - decimal_number_text_field.js.jsf
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131
  • Sorry, I didn't give -1. I have now rearranged JavaScript files, CSS files and image files in the form of a library so that they can be accessed like ``. According to [this](http://stackoverflow.com/a/11988418/1391249) answer. Thank you. – Tiny Jul 23 '13 at 16:42