Reputation: 8606
I want to use <f:loadBundle>
tag in my view. I know that I can declare it inside faces-config.xml
, but for a reason I want to use it in my view. I am using the tag in this manner but it is not working. I am using it inside <ui:composition>
tag.
<h:head>
<title>Email Content</title>
</h:head>
<h:body>
<ui:composition template="./WEB-INF/templates/layout.xhtml">
<ui:define name="content">
<f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
<h:form id="emailContent_Review" >
<p:growl id="growl" showDetail="true" />
<p:panel id="panel"
header="#{msgs.ECR_panelHeader}"
style="border-color: #000000;width: 960px;position: absolute;left: 150px;height: 370px" >
<p:dataTable value="#{emailContent_Review.emailContent}"
var="emailContent"
selection="#{emailContent_Review.selectedEmailContent}"
emptyMessage="#{msgs.ECR_tableEmptyMessage}"
widgetVar="portalsTable"
rows="8" height="350" paginator="true">
<f:facet name="header" >
</f:facet>
</p:dataTable>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</h:body>
What I am doing wrong? Also I read that
To make use of a template, you use a 'ui:composition' tag with a 'template' attribute. Facelets removes all tags outside the tag - that is, the doctype declaration, html, head, title and body tags. This is necessary because the
<ui:composition>
is replaced with the template that contains its own set of html, head, title, and body tags.
If I want to use my properties file in the head section, then how can I use it? Because head section is outside the <ui:composition>
tag. I mean to say, if I want to do this
<h:head>
<title>#{msgs.indexWindowTitle}</title>
</h:head>
then how can I use my properties file outside <ui:composition>
?
Upvotes: 4
Views: 9146
Reputation: 4017
I have struck upon an approach that works well for me on Mojarra 2.1.x, perhaps give it a tumble. Tweaking @BalusC's example:
<ui:composition>
<f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
<ui:decorate template="./WEB-INF/templates/layout.xhtml">
<ui:define name="title">
#{msgs.indexWindowTitle}
</ui:define>
<ui:define name="content">
...
</ui:define>
</ui:decorate>
</ui:composition>
My approach of nesting the templated ui:decorate within my bare ui:composition tags works well for me because I often want to declare one f:loadBundle tag that is shared by all of my nested ui:define's. Not sure what kinds of extra machinations I'm making the kernel do when I do this however, or if I'm exploiting an incomplete implementation of the spec to get what I want. YMMV
Upvotes: 0
Reputation: 1108732
This is indeed not going to work. Change your master template layout.xhtml
to replace the title by a template insert placeholder:
<h:head>
<title><ui:insert name="title">Default title</ui:insert></title>
</h:head>
Then change your template client to define it:
<ui:composition template="./WEB-INF/templates/layout.xhtml">
<ui:define name="title">
<f:loadBundle basename="presentationBeans.homepage.messages" var="msgs"/>
#{msgs.indexWindowTitle}
</ui:define>
<ui:define name="content">
...
</ui:define>
</ui:composition>
Note that you don't need to repeat the <f:loadBundle>
for <ui:define name="content">
.
Upvotes: 5