I have a JSF 2.0 Webapplication into which I d’like to include TinyMCE 3.5.
The way I included it is like below:
<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>
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 byResourceHandlerwhich in turn allows modularization and versioning without the need to ever change the<h:outputScript name>. When theFacesServletis mapped on*.xhtml, the resource URL will look like thisThe TinyMCE scripts are apparently auto-including some other scripts based on the script’s own URL and not taking the
.xhtmlsuffix into account.This will then indeed result in 404s. When you’re using a prefix mapping for the
FacesServletlike/faces/*, then this problem will not occur.One solution is to hardcode the
<script>with the desired URL yourself. The right substitute would then beThe 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.xhtmlsuffix 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.