Search code examples
javascriptjsffacelets

Generating pure javascript/css files using JSF 1.2/Facelets


I need to generate a pure JavaScript file or pure css file dynamically using JSF 1.2/Facelets. When I mean 'pure' I mean without any markup like xml, html open/close tags.

Is this possible? If so what settings do I need to use for the facelets output mechanism.

To give you a bit of history, I am trying to use the TinyMCE editor in my jsf application and to configure the list of images, it is supplied with a file name. The file is read and parsed on the client side and need to be just javascript and nothing else.


Solution

  • If memory serves, JSF 1.2 Facelets mandate producing XHTML. I imagine it is technically possible to do what you want even if you might have to resort to transforming the resultant XML (e.g. using XSLT) in a servlet Filter.

    It would be significantly easier to do using a JSP in the same application:

    <%@ page language="java" contentType="text/javascript; charset=ISO-8859-1"
                                                     pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
    <f:view>
       var foo = '<h:outputText value="#{bar.baz}" escape="false" />';
    </f:view>