通过h:outputScript包含带有资源的javascript [英] Include javascript with resources via h:outputScript

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

问题描述

我想将JScolor包含到我的jsf应用程序中。可以通过< script> 标签,但我的意思是通过< h:outputScript> 更多系统。

I would like to include JScolor to my jsf application. It is possible via <script> tag, but I mean it is more system via <h:outputScript>.

然而,它无法使用资源。 JSColor包含一个js文件和一些图片文件 - 好像包含了js文件而reousrces没有。

However it is not working with resources. JSColor includes one js file and some picture files - it seems like the js file is included and the reousrces not.

有人可以告诉我为什么吗?以及如何解决这个问题?

Could anybody tell me why? And how to solve this?

谢谢。

推荐答案

JS文件显然是通过相对路径引用图片文件,该路径不代表有效的JSF资源URL。

The JS file is apparently referencing picture files via a relative path which do not represent a valid JSF resource URL.

< h:outputScript> 生成一个JSF资源URL,该URL经过JSF资源处理程序,后者担心其中包括自动本地化和版本控制。它将生成一个前缀为 /javax.faces.resource 的URL,并附加当前使用的 FacesServlet URL映射,例如 *。xhtml / faces / *

The <h:outputScript> generates a JSF resource URL which goes through the JSF resource handler which worries about among others automatic localization and versioning. It would generate an URL prefixed with /javax.faces.resource and also append the currently used FacesServlet URL mapping such as *.xhtml or /faces/*.

因此,如果你在 *。xhtml 上映射了面部servlet,并且有一个带有JS的 / resources / jscolor 文件夹,图像文件并引用了JS文件,如下所示,

Thus, if you mapped the faces servlet on *.xhtml and have a /resources/jscolor folder with the JS and image files and have referenced the JS file as follows,

<h:outputScript name="jscolor/jscolor.js" />

然后它会生成

<script type="text/javascript" src="/context/javax.faces.resource/jscolor/jscolor.js.xhtml"></script>

但是, /javax.faces中的图像文件在物理上不可用。 resource / jscolor 文件夹,相反,它们在 / resources / jscolor 文件夹中可用。只有在资源名称上应用faces servlet映射时,才会自动解析 /javax.faces.resource 。因此,只有当您手动编辑 jscolor.js 文件以更改图像文件名时,此特定情况才有效。 arrow.gif arrow.gif.xhtml

However, the image files are not physically available in /javax.faces.resource/jscolor folder, instead they are physically available in /resources/jscolor folder. The /javax.faces.resource would only be automatically resolved when you apply the faces servlet mapping on the resource name. Thus, this specific case would only work if you manually edit the jscolor.js file to change image file names from e.g. arrow.gif to arrow.gif.xhtml.

如果您不使用JSF资源解析程序的任何自动本地化或版本控制功能,也不使用任何需要真正JSF资源而不是静态HTML元素的特殊自定义资源解析程序,例如这个,那么你也可以继续使用普通的HTML < script> 元素而不是< h:outputScript>

If you don't utilize any automatic localization or versioning features of the JSF resource resolver, nor are using any special custom resource resolvers which requires real JSF resources rather than static HTML elements, such as this one, then you can also just go ahead with a plain vanilla HTML <script> element instead of a <h:outputScript>.

<script type="text/javascript" src="#{request.contextPath}/resources/jscolor/jscolor.js"></script>

这篇关于通过h:outputScript包含带有资源的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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