Does it matter whether place f:event inside f:metadata or not?
Asked Answered
A

1

9

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 ?

Ambit answered 8/9, 2011 at 4:47 Comment(0)
W
8

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>.

Whitman answered 8/9, 2011 at 4:51 Comment(1)
Thanks BalusC. I have since found that it does seem to matter whether one places an f:event inside an f:metadata of a template (only): #11069984Ambit

© 2022 - 2024 — McMap. All rights reserved.