Reputation: 1739
I've got this in a page I use to edit 'events'
<f:metadata>
<f:viewParam id="event_id" name="eventId" value="#{eventController.eventId}"/>
<f:event type="preRenderView" listener="#{eventController.loadEvent}" />
</f:metadata>
...and a corresponding loadEvent method in my "ViewScoped" bean.
In a 'list events' page where the user can select which event they want to edit, I build up links like this
<h:link value="Full details" outcome="/calendar/viewEvent" includeViewParams="true">
<f:param name="eventId" value="#{calendarController.event.eventId}" />
</h:link>
I wouldn't expect the loadEvent method to be called until I click on a link, but it gets called once, and once only, when I visit the 'list events' page.
Sure this is down to the JSF-lifecycle somehow... but why?
Upvotes: 0
Views: 658
Reputation: 96
I'm also experiencing this with Mojarra 2.1.10 (I'm assuming you're also on Mojarra?). The bug has already been submitted as JAVASERVERFACES-2158 with no fix or workaround at the time of writing. The problem is this: During preemptive navigation done when rendering UIOutcomeTarget
components such as h:link
and h:button
with view parameters included, the target view is compiled to extract f:viewParam
/UIViewParameter
components from its h:metadata
element. This compilation has a side-effect of also setting up event subscriptions on the current UIViewRoot
based on the f:event
elements . In the normal case – that is when the view returned to the user in the response is being compiled – this is all fine. However, when another view is compiled for the sake of obtaining its view parameters, registering event subscriptions on the current view root (as in FacesContext.getViewRoot()
) is not fine at all.
Upvotes: 3