2

In my tomcat I have defined two context.

One is my application URL, which is

http://localhost:8080/mysite/faces/abc.xhtml

another one is used to put all my static files which maybe used by other applications.

http://localhost:8080/files/myfile.html

In my application .xhtml file I want to include page from the other context, for example

<ui:include src="/files/myfile.html">

But I always get error

javax.faces.view.facelets.TagAttributeException:.....Invalid path : /files/myfile.html

It looks like ui:include is not appropriate to be used here because it only looks for context related path. What should I use then?

flyasfish
  • 119
  • 2
  • 3
  • 11

1 Answers1

4

There are several options:

  1. Use <iframe> instead.

  2. Refactor the shared files into a separate web fragment project which should end up as JAR in /WEB-INF/lib of both webapps. Put the Facelets resources in the /META-INF/resources folder of the separate web fragment project. It'll be available for <ui:include> the usual way: Structure for multiple JSF projects with shared code.

  3. When on JSF 1.x, use a custom com.sun.facelets.impl.DefaultResourceResolver: How to use Facelets composition with files from another context.

  4. When on JSF 2.x, use a custom javax.faces.view.facelets.ResourceResolver: how to share a jsf error page between multiple wars.

  5. When on JSF 2.2+, use a custom javax.faces.application.ResourceHandler: Obtaining Facelets templates/files from an external filesystem or database.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks to BalusC! the iframe can do exactly what I need. The second option is not valid for me because I have other backend applications which will dynamically generate static html pages who should be able to be seen from my web application. – flyasfish Aug 15 '12 at 23:41
  • @BalusC what if i want to load into my JSF page an external HTML resource ? here is my [question](https://stackoverflow.com/questions/24038345/jsf-tag-that-load-html-from-external-source) – Mifmif Jun 05 '14 at 09:16
  • Would a custom resource resolver be a solution too? https://stackoverflow.com/questions/5587808/how-to-use-facelets-composition-with-files-from-another-context – Kukeltje Feb 03 '18 at 21:22
  • @Kukeltje: Indeed. – BalusC Feb 04 '18 at 07:31