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>
2
  • In the generated html i get this line: <script type="text/javascript" src="RES_NOT_FOUND"></script> Commented Oct 29, 2011 at 0:44
  • 1
    i dont know jsf try name="./js/messages.js" Commented Oct 29, 2011 at 1:48

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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 stackoverflow.com/questions/7132061/… and stackoverflow.com/questions/7927716/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.