only partially works when page called via commandLink

UI Components for JSF
Post Reply
webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

28 Sep 2010, 00:49

Primefaces2.2M1
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"/>
The method prepareEditShared() just loads various

Code: Select all

Long[] selectedElementIds
used to set the state of various form multi-select widgets. I can make it do nothing and the problem still occurs, it is probably not the culprit. It returns the navigation case "edit".

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"
or

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>
where prepareEditSharedListener just calls prepareEditSharedListener.

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>
Works like a charm ! All primefaces widgets then display and operate correctly in the edit.xhtml form. Until one submits deliberately with validation error, then on rerender of the edit form with error message the primefaces widgets are again either inoperable (like p:calendar) or faulty (like p:panel).

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
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

28 Sep 2010, 01:13

I can't reproduce this problem using a minimal test project.

I created a very simple top-level view.xhtml that calls edit.xhtml 2 different ways, once with h:link, once with h:commandLink via a TestBean.prepareEdit() method returning "edit", and both worked fine.

There must be something different in my live project, but it is too large to post here. Will try to isolate difference ..
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 51 guests