如何通过 h:outputScript 包含 JavaScript 文件? [英] How to include JavaScript files by h:outputScript?

查看:27
本文介绍了如何通过 h:outputScript 包含 JavaScript 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 jQuery Validate 插件与 JSF 一起用于客户端表单验证.我在导入资源时遇到了基本困难.

I want to use jQuery Validate plugin with JSF for client side form validation. I am finding basic difficulty in importing the resources.

在我的 JSF 页面中

In my JSF page I have

<h:outputScript library="js" name="jquery-1.6.2.js"></h:outputScript>
<h:outputScript library="js" name="jquery.validate.js"></h:outputScript>
<h:outputScript library="js" name="jquery.maskedinput.js"></h:outputScript>
<h:outputScript library="js" name="myapp.validate.js"></h:outputScript>

当我在 Firefox 中单击脚本选项卡时,在下拉列表中看不到任何脚本文件.有一条消息显示:

When I click on the script tab in the Firefox, I can't see any script files in the dropdown. There is a message shown:

如果标签有一个type"属性,它应该等于text/javascript"或application/javascript".此外,脚本必须是可解析的(语法正确).

If tags have a "type" attribute, it should equal "text/javascript" or "application/javascript". Also scripts must be parsable (syntactically correct).

此外,我的 jquery 效果如鼠标悬停、隐藏、显示等不起作用.我尝试使用通常的脚本标签

Futher my jquery effect like mouse hover, hide, show etc do not work. I tried with usual script tags

<script type="text/javascript" src="../js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="../js/jquery.validate.js"></script>
<script type="text/javascript" src="../js/jquery.maskedinput.js"></script>
<script type="text/javascript" src="../js/myapp.validate.js"></script>

这没有用.它仍然无法找到我的 JS 文件.我所有的JS文件都放在

Which was of no use. Still it was not able to locate my JS files. All my JS files are placed under

   Web pages
       |_ js
           |_jquery-1.6.2.js,my.validate.js,jquery.validate.js,jquery.maskedinput.js

我尝试了发布在 使用 jQuery 的解决方案之一使用 JSF 2.0 的资源,但没有成功.

I tried one of the solutions posted at Using jQuery with JSF 2.0's resource but had no success.

请建议我解决这个问题.我不想在 ajax 中使用 JSF 内置验证,因为我们将代码从 JSP 移到 JSF,并且验证已经编写.我想重用我之前编写的现有 jQuery 验证.

Kindly suggest me a solution for this. I don't want to use JSF builtin validation with ajax, because we moved the code from JSP to JSF and the validation is already written. I want to reuse the existing jQuery Validation which I previously wrote.

推荐答案

(和 )从/resources 文件夹.您需要将脚本放在该文件夹中.

The <h:outputScript> (and <h:outputStylesheet>) loads resources from /resources folder. You need to put the scripts in that folder.

WebContent
|-- resources
|    `-- js
|        |-- jquery-1.6.2.js
|        |-- myapp.validate.js
|        |-- jquery.validate.js
|        `-- jquery.maskedinput.js
|-- WEB-INF
:

那么以下脚本声明应该有效:

Then the following script declarations should work:

<h:outputScript name="js/jquery-1.6.2.js" />
<h:outputScript name="js/jquery.validate.js" />
<h:outputScript name="js/jquery.maskedinput.js" />
<h:outputScript name="js/myapp.validate.js" />

(请注意,我省略了 library 属性,因为名称js"并不表示 真正的图书馆)

(note that I omitted the library attribute, because the name "js" does not indicate a real library)

您的

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆