-1

I have loaded javascript from Java call in xhtml file. When I opened the browser in debug mode( both IE and chrome) , javascripts are loading with .xhtml extensions.

Below is the code I am using

<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ice:outputText nospan="true" value="#{msgs.loginTitle}" /></title>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<ice:outputText value="#{MyAction.javaScripts}" visible="false" />
</h:head>

Here JavaScripts is the methods and it returns String.

value="#{MyAction.javaScripts}" Return the below string

<script src="../js/myJs.js" type="text/javascript"></script>

But when I open the browser in debug mode my javascript is like abc.js.xhtml?xxx and some of the functions are not working. My questions are

1) Will java script work perfectly even if it is showing like this?

2) Is the Browser changing the extension or it is configuration issue?

Please help me

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Raj
  • 2,463
  • 10
  • 36
  • 52

1 Answers1

-1

Javascript files should be included in your JSF .xhtml file by using either <h:outputScript> or <script>:

(referencing a script file named 'help.js' in the /js folder)

<h:outputScript library="js" name="help.js" />

or

(embedded script directly within the page)

<script type="text/javascript">

   function sayHello(){
      alert('Hello');
   }

</script>
Hatley
  • 217
  • 2
  • 11
  • Any comment as to why this is wrong or why it was downvoted? Please help improve the question or answer.... – Hatley Jul 27 '16 at 19:24
  • @ Hatley , Second solution wont work for me as my js file contains lot of functions and I have already tried first option and still its not working – Raj Jul 28 '16 at 05:36
  • Downvoting because it did not work for *you* is not very nice. Other people might have similar problems and Hatley's answer could work for them. – the digitalmouse Jul 28 '16 at 05:54
  • The 'answer' does not answer the question and does not even come close. Try what is in the answer and inspect the browser developer tool. What is the extension? Although the question is badly formatted/bad examples, it is _"why am I getting this extension"_. If you look at the source in the browser of the PF showcase, it has those to.I'm inclined to downvote to. – Kukeltje Jul 28 '16 at 07:25
  • @Kukeltje Thanks for suggetion: I have updated the question accordingly – Raj Jul 28 '16 at 07:51
  • 1
    This "answer" was downvoted because 1) It did not answer the question. 2) It introduces a bad practice which is misleading to starters. Upvoting an answer merely because it was downvoted (and thus not because of its bad content) is dangerous for the credibility of Stack Overflow. Don't do that anymore, @thedigitalmouse. – BalusC Jul 28 '16 at 10:53
  • 1
    @BalusC for my benefit and others viewing this, would you clarify what is the bad practice described, so that we can recognize it going forward? Many thanks for your help on this and the (literally) _thousands_ of other JSF-related answer's you've provided on SO! – Hatley Jul 28 '16 at 17:23