Facelet components layouts and javascript
Posted
by Java Drinker
on Stack Overflow
See other posts from Stack Overflow
or by Java Drinker
Published on 2010-06-15T18:48:38Z
Indexed on
2010/06/15
18:52 UTC
Read the original article
Hit count: 230
Hi all, I have a question regarding the placement of javascript within facelet components. This is more regarding best practice/style than a programming issue, but I feel like all the solutions I have thought of have been hacks at best. Ok here is my scenario:
I have a facelet template like so (my faces, and apache Trinidad)...
<ui:composition>
<f:view locale="#{myLocale}">
<ui:insert name="messageBundles" /><!--Here we add load bundle tags-->
<tr:document mode="strict" styleClass="coolStyleDoc">
<f:facet name="metaContainer">
<!--This trinidad defined facet is added to HTML head-->
<tr:group> <!-- blah bal my own styles and js common to all -->
<ui:insert name="metaData" />
</tr:group>
</f:facet>
<tr:form usesUpload="#{empty usesUpload ? 'false' : usesUpload}">
<div id="formTemplateHeader">
<ui:insert name="contentHeader" />
</div>
<div id="formTemplateContentContainer">
<div id="formTemplateContent">
<ui:insert name="contentBody" />
</div>
</div>
<div id="formTemplateFooter">
<ui:insert name="contentFooter">
</ui:insert>
</div>
</tr:form>
<!-- etc...--->
Now, a facelet that wants to use this template would look like the following:
<ui:composition template="/path/to/my/template.jspx">
<ui:define name="bundles">
<custom:loadBundle basename="messagesStuff" var="bundle" />
</ui:define>
<ui:define name="metaData">
<script>
<!-- cool javascript stuff goes here-->
</script>
</ui:define>
<ui:define name="contentHeader">
<!-- MY HEADING!-->
</ui:define>
<ui:define name="contentBody">
<!-- MY Body!-->
</ui:define>
<ui:define name="contentFooter">
<!-- Copyright/footer stuff!-->
</ui:define>
</ui:composition>
All this works quite well, but the problem I have is when I want to use a facelet component inside this page. If the facelet component has its own javascript code (jQuery stuff etc), how can I make it so that that javascript code is included in the header section of the generated html? Any help would be appreciated. Please let me know if this is not clear or something... thanks in advance
© Stack Overflow or respective owner