Can't get ajax rowSelect event to fire on PrimeFaces DataTable

20,631

you must add : selection="#{forumManagedBean.selectedPost}"

inside your the setter you can display the selected object:

public void setSelectedPost(ForumPost post){
            if(post!=null){
                          System.out.println("Hello World"+post);
                           }
             this.selectedPost=selectedPost;
}

the ajax event in there like so:

<p:ajax event="rowSelect" update=":mainForm:displayPost"/>
Share:
20,631

Related videos on Youtube

user489041
Author by

user489041

Updated on October 17, 2020

Comments

  • user489041
    user489041 over 3 years

    I am using a PrimeFace DataTable. I want to add the ajax rowSelect event to it. However, when a row is clicked, the event is not fired.

    My table is decalred like so:

    <h:from>
    ....
    <h:panelGroup id="forumPanelGroup" layout="block" styleClass="messagesPanel" rendered="#{socialAdvertiserTemplateManagedBean.displayForum}" >
                <p:dataTable 
                    id="forumDataTable"
                    resizableColumns="true"
                    var="post" 
                    value="#{forumManagedBean.posts}" 
                    scrollable="true"
                    scrollHeight="300"
                    paginator="true"
                    rows="10"
                    rowKey="#{post.id_value}"
                    emptyMessage="No posts found for the given criteria"
                    widgetVar="forumTable"
                    selectionMode="single"
                    tableStyle="width:auto" 
                    paginatorPosition="top">
    

    I have the ajax event in there like so:

    <p:ajax event="rowSelect" update=":mainForm:displayPost" listener="#{forumManagedBean.rowSelect}" />
    

    And in my backing bean, I have this function:

    public void rowSelect(SelectEvent selectEvent)
    {
        System.out.println("Hello World");
        ForumPost post = (ForumPost) selectEvent.getObject();
        selectedPost = post;
    }
    

    Can anyone see a problem with my declaration that would cause the event to not be triggered. I even looked at it in FireBug, and saw this being submitted after a row is clicked:

    javax.faces.ViewState   1786545179464296127:-2498355873814808136
    javax.faces.behavior.even...    rowSelect
    javax.faces.partial.ajax    true
    javax.faces.partial.event   rowSelect
    javax.faces.partial.execu...    mainForm:forumDataTable
    javax.faces.partial.rende...    mainForm:displayPost
    javax.faces.source  mainForm:forumDataTable
    mainForm    mainForm
    mainForm:forumDataTable_i...    1
    mainForm:forumDataTable_s...    0,0
    mainForm:forumDataTable_s...    1
    mainForm:j_idt181_active    0
    mainForm:j_idt70    
    mainForm:j_idt72    
    

    So it looks like it is sending the rowSelect. But my server side isnt picking it up.

    • Darka
      Darka over 10 years
      maybe wrong scope? try to use ViewScoped.