Glassfish3.0.1
mojarra-2.0.3-FCS
I have a strange situation where Primefaces widgets are only working properly for me when
calling an edit page with a form directly using an h:link with query parameter, but not when using a commandLink.
It also does not work properly when I the edit page is rerendered with a validation error message after a validation fails.
Background: I have a range of entities, and for each entity T there is a matching session scoped @ManagedBean "manager".
For example, for an Activity I have a session scoped managed bean ActivityManager. (Some might prefer the term Controller).
ActivityManager maintains a reference to a 'current' or 'selected' Activity, which it uses to display output fields in /activity/view.xhtml
and for input fields in /activity/edit.xhtml. (In fact, for efficiency, every manager like ActivityManager extends a generic AbstractManager<T extends Element>, where Activity is an Element.)
view.xhtml has an Edit link to edit.xhtml.
There are (at least) 2 possibilities for creating the link to edit.xhtml, both of which must at some stage call a method prepareEditShared() to setup things like the state of editing widgets.
Using a commandLink does not play nice with Primefaces for me; using a plain link (with viewParam extraction and preRenderView event) does. Also, using a commandButton to save the form with a reload due to validation error also plays badly with Primefaces for me.
Here is the typical commandLink from view.xhtml to edit.xhtml:
Code: Select all
<h:commandLink action="#{activityManager.prepareEditShared}" value="Edit"/>
Code: Select all
Long[] selectedElementIds
When I invoke the edit.xhtml using such a commandLink from a view.xhtml Primefaces does not display properly. Initially I tried a p:calendar and it showed nothing at all. I then tried inserting some other primefaces widgets like p:panel, they displayed, but not properly, they did not show the buttons for
Code: Select all
toggleable="true"
Code: Select all
closable="true"
I tried the same primefaces widgets in standalone pages, both at the top level context and within my /activity folder at the same level as my view.xthml and edit.xhtml and they worked fine.
By complete chance I noticed that when I load /activity/edit.xhtml directly from the browser address bar (relying on the previous state of the selected/current activity in the session scoped ActivityManager) it works perfectly, the primefaces widgets display and act as expected.
So I then I tried a bookmarkable URLs approach passing query parameter to the JSF page. I introduced the following into the head of /activity/edit.xhtml:
Code: Select all
<f:view>
<f:metadata>
<f:viewParam name="id" value="#{activityManager.id}"/>
<f:event type="preRenderView" listener="#{activityManager.prepareEditSharedListener}"/>
</f:metadata>
</f:view>
This is then called directly from the browser URL bar using a query parameter, or from /activity/view.xhtml or elsewhere using:
Code: Select all
<h:link outcome="edit" value="Edit">
<f:param name="id" value="#{activityManager.selected.id}"/>
</h:link>
I am absolutely bamboozled by this problem and would be very grateful for an explanation and solution.
I have a perfectly standard Primefaces setup for JSF 2.0 with PrimeFaces 2.x after the Primefaces users guide 260710.
glad for help,
Webel