使用JSF h:outputScript时找不到TinyMCE .js文件 [英] TinyMCE .js files not found when using JSF h:outputScript

查看:75
本文介绍了使用JSF h:outputScript时找不到TinyMCE .js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个希望包含TinyMCE 3.5的JSF 2.0 Web应用程序.

我包含它的方式如下:

<composite:implementation>
    <h:outputScript name="tiny_mce/tiny_mce.js"/>
    <h:outputScript name="js/tinymce_init.js"/>
    <h:inputTextarea rows="5" cols="80" styleClass="tinymce" value="#{cc.attrs.value}"/>
</composite:implementation>

现在一切正常.我唯一的问题是"tiny_mce.js"在tiny_mce文件夹中具有对其他js文件的某些引用.这些引用返回404错误,因为它们没有.xhtml结尾.

示例:tiny_mce.js引用了en.js.它试图从" http://localhost加载它: 8080/briefe/javax.faces.resource/js/tiny_mce/langs/en.js ".如果我在浏览器中输入该URL,则会得到404.如果我在末尾添加.xhtml("<​​a href =" http://localhost:8080/briefe/javax.faces.resource/js/tiny_mce/langs/en.js.xhtml"rel =" nofollow> http://localhost:8080/briefe/javax.faces.resource/js/tiny_mce/langs/en.js.xhtml "),一切正常. /p>

所以我想问你,是否有办法将xhtml添加为.js文件的默认结尾,或者是否有办法使.js文件可访问.

解决方案

<h:outputScript>将生成一个JSF资源URL,该URL由ResourceHandler处理,从而允许进行模块化和版本控制,而无需更改.当FacesServlet映射到*.xhtml时,资源URL将如下所示:

/contextname/javax.faces.resource/filename.js.xhtml

TinyMCE脚本显然是自动添加的,其中包括一些基于脚本自身URL的其他脚本,而没有考虑.xhtml后缀.

/contextname/javax.faces.resource/otherfile.js

这确实会导致404.当您将FacesServlet的前缀映射用于/faces/*时,则不会发生此问题.

一种解决方案是自己用所需的URL对<script>进行硬编码.正确的替代者将是

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

唯一的缺点是,当您在单个视图中使用多个复合组件时,最终将在主体中包含多个<script>条目,而不是仅由<h:outputScript>注意的一项.这可能会导致JavaScript冲突/错误.如果遇到此问题,我将考虑相应地破解/修复TinyMCE JavaScript文件,以将.xhtml后缀添加到URL,以便您可以继续使用<h:outputScript>.或者,您当然可以使用现有的即用型JSF RTF文本编辑器组件,例如

Now everything works fine. The only problem I have is that "tiny_mce.js" has some references to other js files in the tiny_mce folder. These references return a 404 error, because they have no .xhtml ending.

Example: tiny_mce.js references en.js. Its trying to load it from "http://localhost:8080/briefe/javax.faces.resource/js/tiny_mce/langs/en.js". If I enter this URL into the Browser I get a 404. If I add .xhtml in the end ("http://localhost:8080/briefe/javax.faces.resource/js/tiny_mce/langs/en.js.xhtml") everything works great.

So I d like to ask you, if there is a way I can add xhtml as default ending for .js files or if there is a way to make .js files accessible.

解决方案

The <h:outputScript> will generate a JSF resource URL which is handled by ResourceHandler which in turn allows modularization and versioning without the need to ever change the <h:outputScript name>. When the FacesServlet is mapped on *.xhtml, the resource URL will look like this

/contextname/javax.faces.resource/filename.js.xhtml

The TinyMCE scripts are apparently auto-including some other scripts based on the script's own URL and not taking the .xhtml suffix into account.

/contextname/javax.faces.resource/otherfile.js

This will then indeed result in 404s. When you're using a prefix mapping for the FacesServlet like /faces/*, then this problem will not occur.

One solution is to hardcode the <script> with the desired URL yourself. The right substitute would then be

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

The only disadvantage is, when you're using multiple composite components in a single view, then you'd end up with multiple <script> entries in the body instead of only one as taken care by <h:outputScript>. This may end up in JavaScript conflicts/errors. If you encounter this problem, I'd consider to hack/fix the TinyMCE JavaScript file accordingly that it adds the .xhtml suffix to the URL, so that you can keep using <h:outputScript>. Or, you can of course use an existing and ready-to-use JSF rich text editor component such as PrimeFaces <p:textEditor>, so that you don't need to worry about this all.

这篇关于使用JSF h:outputScript时找不到TinyMCE .js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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