I will ilustrate my question using an example:
outerfile.xhtml:
<h:head>
<h:outputScript library="js" name="jquery-1.6.2.js" />
<h:outputScript library="js" name="outer.js" />
</h:head>
<h:body>
<h:panelGroup id="inner_panel">
<ui:include src="innerfile.xhtml" />
</h:panelGroup>
</h:body>
innerfile.xhtml:
<ui:composition ... >
<h:head>
<h:outputScript library="js" name="jquery-1.6.2.js" />
<h:outputScript library="js" name="inner.js" />
</h:head>
<h:body>
<h:panelGroup>
I Am Text in The Inner File!
</h:panelGroup>
</h:body>
</ui:composition>
My questions:
- Is it okay to declare the
jsfiles in the inner file the way I did? - Do I need (And Should I) declare the common (
jquery-1.6.2.js) again in the inner file? - What happens if I un-render and the re-render
inner_panelusing AJAX? Will the inner-included headers be reloaded?
No. You should not specify the
<h:head>in the include as well. This would only result in invalid HTML. As you have right now will result in:(rightclick page in browser and do View Source to see it yourself, w3-validate if necessary)
Fix it accordingly in
innerfile.xhtml:This will result in valid HTML. The scripts declared by
<h:outputScript target="head">will just end up in the<head>automatically, if not already declared before. Like as in real HTML, there should be only one<h:head>and<h:body>in the entire view, including any templates and include files.Not if the parent file has it already declared as
<h:outputScript>. But redeclaring it in the include doesn’t harm. It won’t be duplicated anyway if it’s already been declared before.This only works if you don’t use
target="head". Whether they will be reloaded from the server, depends on whether it’s already been requested by the browser before and already present and valid in the browser cache. But basically, the browser will be told again to load it, yes. With Firebug you can easily determine it.