3

I have a jsf component that must access to a javascript file, i added this whith outputScript as in the code bellow, I get an error in the generated html, and the javascript can't be reached. The javascript file is located in document_root/js directory

How can i resolve this problem, thank you for your help.

<!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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head><title>(For validation only)</title>
<link href="./css/styles.css" 
      rel="stylesheet" type="text/css"/> 
</h:head>
<h:body>
<composite:interface/>
<composite:implementation>
<h:outputScript library="js" name="messages.js" />
<h:outputScript library="js" name="DateValidation.js" />

<h:form id="f">
    <h:outputText value="Date" />
    <h:inputText id="dateA" 
        onblur="return validateDateField('f:dateA');">
    </h:inputText>
</h:form>   

</composite:implementation>

</h:body>
</html>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Aziz Mehdaoui
  • 257
  • 1
  • 7
  • 16

1 Answers1

3

Those files have to be placed in the /resources subfolder. So, you should have the following in the public webcontent:

  • /resources/js/DateValidation.js
  • /resources/js/messages.js

Unrelated to the concrete problem, your composite component approach is pretty awkward. I'd suggest to check out tag wiki: https://stackoverflow.com/tags/composite-component/info

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you very much for your answer, I can now reach the javascript file but I get a javascript error because the id of my inputText is prepend whith j_idt6 so the id of my inputText became j_idt6:f:dateA instead of f:dateA. have you please an idea to get around this issue. – Aziz Mehdaoui Oct 29 '11 at 10:39
  • That's a different problem for which you should in essence have asked a new question. It has however already been asked several times before, see also http://stackoverflow.com/questions/7132061/how-to-refer-to-a-jsf-component-id-in-jquery and http://stackoverflow.com/questions/7927716/how-to-select-primefaces-ui-or-jsf-components-using-jquery – BalusC Oct 29 '11 at 19:11