3

I am unable to reach my backing beans method when calling it in a <p:commandLink> inside a datatable column.

My commandlink works fine when put outside the datatable, but then I cannot directly pass the selected row variable.

Here is my code:

              <h:form id="reviewLists" prependId="false">         
                <p:messages  />  
                <p:panel header="Beoordelingen" style="margin-bottom:10px;">              
                    <p:dataTable value="#{reviewFinderBean.employees}" var="employee" >
                        <p:column headerText="Medewerker" >
                            <h:commandLink value="#{employee.name}" action="#{reviewFinderBean.showReviewsForEmployee(employee)}" />                  
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>

When checking the http requests my browser makes I see it does another post (ajax) as expected, I have tried to use prependId="false" as I thaught the generated component names might have been unresovable but that didnt help.

The ajax post is fired but somehow is never resolved to the correct backingbean method on the server

<f:setPropertyActionListener> also doesnt resolve to any property when set correctly and used in the the datatable column.

Nick Hol
  • 302
  • 1
  • 10

1 Answers1

1

First of all, get rid of prependId="false". It makes things worse in ajax processing and updates.

In order to fix the problem, you need to rewrite the bean in such way that it returns exactly the same data model (the value behind #{reviewFinderBean.employees}") during processing the form submit as it was during displaying the form. JSF will namely re-iterate over it in order to find the associated row where the command is been invoked.

If you want to keep the bean in the request scope, then you need to recreate exactly the same datamodel in its (post)constructor. If your bean is already in the view scope, then you need to make sure that the getter method is totally free of business logic so that the data model don't potentially change.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks. I was already recreating the data model in a @PostConstruct method but the reacreated data model was based on specific parameters from search queries which reset during a new request. I've now changed the scope and everything works fine. – Nick Hol Apr 18 '13 at 13:12