w.r.t. How to execute action on GET request with f:viewParam?
<f:metadata>
<f:viewParam name="id" value="#{tInputBean.id}" />
<f:event type="preRenderView" listener="#{tInputBean.init}" />
</f:metadata>
I'm interested to know whether it matters if a preRenderView
f:event
is placed inside the f:metadata or not. I've checked the Java EE6 tutorial, Java Server Faces 2.0 Complete Reference, and Core JSF2, and none of them have examples of f:event inside f:metadata, but I've seen lots of examples online like this.
JSF2 Compl.Ref says p.540
The f:metadata tag encapsulates the set of elements used to specify the metadata for a Facelet view, and therefore must be a child of the f:view tag and may not appear in a template. As of JSF2.0, the only purpose of this tag is to encapsulate f:viewParam tags.
Does placing the f:event (often used to support an f:viewParam) inside the f:metadata have a special meaning, or is it just to help group it alongside the f:viewParam visually/logically ?
No, the <f:event>
is not strictly required to be placed inside <f:metadata>
. It can be attached to any component. It's indeed for pure self-documentary purposes placed inside the <f:metadata>
whenever you have a bunch of <f:viewParam>
s and would like to hook a <f:event>
to invoke an action after all those view parameters have been set. It can even be placed outside/before those <f:viewParam>
s, but it makes the code not more self-documenting.
Note that in the upcoming JSF 2.2, a new <f:viewAction>
tag will be introduced which in turn is supposed to replace the <f:event type="preRenderView">
in the <f:metadata>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With