0

I am trying to list all jsf files that are included (e.g. via ui:include) in the current page. I was hoping that I can find that information somehow on each UIComponent so that I just had to iterate over all UIComponents on that page and add the source file to a set but I can't find anything that would give me the source file.

Any ideas?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Ben
  • 1,922
  • 3
  • 23
  • 37
  • Next to impossible (I think). You'd have to see if e.g. a `ui:include` has some dynamics in it. If a template is used and then see what is used in there... Sounds kind of difficult to me. But let me as a question: Why would you want to? Very, very uncommon thing (first in 15 years) – Kukeltje May 17 '17 at 13:31
  • We are migrating a large JSF app from RichFaces to PrimeFaces and over the years we have accumulated a lot of xhtml files and also a lot of dead code. So it would be nice to see which files need to be converted for a particular 'main' page. – Ben May 19 '17 at 12:37
  • I had an idea this morning. Maybe you can create a custom ResourceResolver which extends the basic/default one and in it log the 'URL' and any xhtml file it tries to resolve (and pass the request on to the original resolver). See http://stackoverflow.com/questions/13292272/obtaining-facelets-templates-files-from-an-external-filesystem-or-database – Kukeltje May 20 '17 at 07:04
  • Thanks that worked like a treat! Why don't you post it as an answer then I can accept it as the correct answer. – Ben May 24 '17 at 10:19
  • Great! Can you post the code as an answer please. – Kukeltje May 24 '17 at 10:20

1 Answers1

0

Kukeltje's suggestion to check out BalusC's (who else?) post Obtaining Facelets templates/files from an external filesystem or database was the answer.

So in order to list all includes for the page that is being loaded use the following:

As I am using JSF 2.1 here is my solution:

import java.io.File;
import   java.net.MalformedURLException;

import java.net.URL;

import javax.faces.FacesException;
import javax.faces.view.facelets.ResourceResolver;

import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;

public class FacesResourceResolver extends ResourceResolver {
        private ResourceResolver parent;

        public FacesResourceResolver(ResourceResolver parent) {
            this.parent = parent;
        }


        private static final Log log = Logging
                .getLog(FacesResourceResolver.class);

        @Override
        public URL resolveUrl(String path) {


            URL url = parent.resolveUrl(path); 
            log.info("Resource #0", path);

            return url;
        }
}

And add the following to web.xml

<context-param>
    <param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
    <param-value>com.locuslive.odyssey.developer.FacesResourceResolver</param-value>
</context-param>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Ben
  • 1,922
  • 3
  • 23
  • 37