I have the following part of a .xhtml page:
<ui:composition template="./templates/template.xhtml">
<ui:define name="mainContent">
<ui:include src="include/includeAbleEditor.xhtml">
<ui:param name="includeParam" value="MyClass" />
</ui:include>
<ui:include src="include/includeAbleEditor.xhtml">
<ui:param name="includeParam" value="YourClass" />
</ui:include>
</ui:define>
In the "includeAbleEditor.xhtml" I want to call a method after it was included (In this case this should happend two times).
Now I tried to solve it like this: (metadata tag is part of the includeAbleEditor.xhtml)
<f:metadata>
<f:event type="preRenderView" listener="#{editor.onload}" />
<f:attribute name="textFieldId" value="#{includeParam}" />
</f:metadata>
The Problem:
The method is being called only once. But it should be called two times. Once with the parameter "MyClass" and once with "YourClass".
Do you have any suggestions?
Thanks a lot!
There can be only one
<f:metadata>
in the entire view and it must be in the top level view. Unlike e.g.<f:view>
, they don't "extend" each other and all others will be ignored.You actually don't need it here. It's only necessary whenever you need to attach
<f:viewParam>
and/or<f:viewAction>
to the specific view. The<f:event>
doesn't require a<f:metadata>
. It will just be hooked to the parentUIComponent
. It was during JSF 2.0/2.1 ages (when<f:viewAction>
didn't exist) being abused to have a hook to invoke a listener after<f:viewParam>
values are being set. It's just for self-documentary purposes being placed in the same<f:metadata>
as where all<f:viewParam>
s are.So, just get rid of it.
That said,
postAddToView
is likely a better event to hook this all on. And to avoid "Duplicate component ID" errors over all place later on, consider wrapping it in<f:subview>
or making it a composite.See also: