0

I have a web application and I would dynamicaly load external JSF files, for exmaple, by a form on a page.

Is possible to load a JSF page as string (file outside the WAR) and pass it to the Face Servlet for interpreting?

micuss
  • 15
  • 2

1 Answers1

1

I don't know what you are meaning exactly with "dynamicaly load external JSF files". If you want to replace parts of the view via ajax with snippets you are storing in separate file you could do this:

<h:commandButton value="click me">
    <f:ajax render="panel" listener="#{bean.actionListener}" />
</h:commandButton>

<h:panelGroup id="panel">
    <h:panelGroup rendered="#{bean.condition}">
        <ui:include src="snippet.xhtml" />
    </h:panelGroup>
    <h:panelGroup rendered="#{bean.anotherCondition}">
        <ui:include src="snippet2.xhtml" />
    </h:panelGroup>
</h:panelGroup>

Make an ajax-call and rerender a panelGroup. In this panelGroup you can render your files based on some conditions.

Update: How to load external Facelets via a ResourceResolver is discussed here and here.

Community
  • 1
  • 1
lefloh
  • 10,653
  • 3
  • 28
  • 50
  • Ok, I think I did not explain this precisely. I want to load in my web app a JSF page which is placed in some directory on server, for emaple under C:\myPages\myfile.xhtml. Is that possible? – micuss Jun 29 '13 at 12:53
  • 1
    Sorry, I missunderstood you. This can be done by a custom [ResourceResolver](http://docs.oracle.com/javaee/6/api/javax/faces/view/facelets/ResourceResolver.html). Normally you would load the files from the classpath, but you could try different ways. See [this question](http://stackoverflow.com/questions/5587808/how-to-use-facelets-composition-with-files-from-another-context). – lefloh Jun 29 '13 at 13:14