Reputation: 28294
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.
Upvotes: 3
Views: 21732
Reputation: 27
I'm assuming you just made a typo at your form while copy-pasting here:
<h:from>
Otherwise, you should get an error with that line. Add an id to your form, so you will be able to reach it when updating.
Adding a selection to your dataTable besides selectionMode will solve your problem:
selectionMode="single" selection="#{forumManagedBean.selectedPost}"
Upvotes: -1
Reputation: 377
I had similar problem because click event on elements inside cell didnt propagate to the cell itself. First you check do you have any errors in console regarding update element, then add selection attribute as it is mentioned in answers above. If all that doesnt help try to add onclick="this.parentElement.click();" to top child element inside tablecell (datatable column).
Upvotes: 0
Reputation: 177
In place of using :mainForm:displayPost
use update="@[id$=displayPost]"
this will pick up displayPost directly no need to map it to any thing.
Upvotes: 0
Reputation: 69
i think your problem is:
<p:ajax event="rowSelect" update=":mainForm:displayPost" listener="#{forumManagedBean.rowSelect}" />
event can not be triggered, because "mainForm" can not be found; you should add an ID to your h:form:
<h:form id="mainForm">
Upvotes: 0
Reputation:
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"/>
Upvotes: 5