4 Replies Latest reply on Jan 28, 2010 4:07 AM by Andreas Panagiotidis

    Load Resources (JS & CSS) from a servlet

    Andreas Panagiotidis Novice



      My question is how to load a JavaScript / CSS Resource file from a servlet, using the ajax4jsf API.


      My goal is to concatenate all the JavaScripts and all the CSS files to a single file, after the rendering of the pages

      I have added a Filter in my web.xml after the seam filter, which works fine.


      I cannot quite understand which classes from the ajax4jsf interface to use to load the resources as InputStreams.


      Here's my filters code:

      public class PackFilter implements Filter {


          public void doFilter(ServletRequest req, ServletResponse res,
                   FilterChain chain) throws IOException, ServletException {


              HttpServletRequest request = (HttpServletRequest) req;

               HttpServletResponse newResponse = new CharResponseWrapper(
                       (HttpServletResponse) res);


              chain.doFilter(req, newResponse);


              String text = newResponse.toString();


              if (text != null) {

              String sourceURI = "org/richfaces/renderkit/html/scripts/skinning.js";
               //String sourceURIFull =  "/my-web/a4j/g/3_3_2.SR1org/richfaces/renderkit/html/scripts/skinning.js";
               LoadResourceRendererBase rb = new LoadResourceRendererBase ();
               InternetResource internetResource;

              //unsuccessful efforts
               //internetResource = rb.getResource(sourceURIFull);       
               //internetResource = new org.ajax4jsf.javascript.AjaxScript();

              //InputStream inputStream
               ClientScript clientScript = new org.ajax4jsf.javascript.AjaxScript();

               InternetResourceBuilder resourceBuilder = InternetResourceBuilder.getInstance();