Can't access javascript file in jsf component

二次信任 提交于 2019-12-23 16:43:21

问题


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>

回答1:


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 composite-component tag wiki: https://stackoverflow.com/tags/composite-component/info



来源:https://stackoverflow.com/questions/7936218/cant-access-javascript-file-in-jsf-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!