I have a datatable with a number of columns that can only be determined at runtime. Hence, I need to implement a data table with dynamic columns (using the "<p:columns>" element).
In addition, there is a requirement that when a user right-clicks on a row in the table, a context menu must pop up with a single menu item. And if the user clicks the menu item I need to call a JavaScript function (that someone else wrote) with the selected row identifier as the input parameter.
I have tried something similar to this:
Code: Select all
<p:contextMenu for="abcTable">
<p:menuitem value="Show Details" onclick="displayDetails(***id***);" />
</p:contextMenu>
<p:dataTable id="abcTable" var="row" value="#{ABCBean.valueList}" rowKey="#{row.record.id}"
selection="#{ABCBean.selectedRecord}" selectionMode="single">
<p:columns columnIndexVar="index" id="#{row.data[index]}_#{index}" value="#{ABCBean.columns}" var="col">
<f:facet name="header">
<h:outputText value="#{col.name}" />
</f:facet>
<h:outputText value="#{row.data[index]}" />
</p:columns>
</p:dataTable>
Has anyone else encountered a similar problem? If "yes", did you get it to work?
BTW: The method ABCBean.getValueList() method returns a list of beans (of type DisplayBean) and the DisplayBean look as shown below:
Code: Select all
package xxx.yyy.zzz;
import java.io.Serializable;
import java.util.ArrayList;
public class DisplayBean implements Serializable
{
private ArrayList<String> data;
private RecordBean record;
public ArrayList<String> getData()
{
return data;
}
public void setData(ArrayList<String> data)
{
this.data = data;
}
public DisplayBean(ArrayList<String> data, RecordBean record)
{
super();
this.data = data;
this.record = record;
}
public RecordBean getRecord()
{
return record;
}
public void setRecord(RecordBean record)
{
this.record = record;
}
}
When I try out this code (I have removed the "onclick" attribute from <p:menuitem>) and select the "Show Details" menu item, I get an error message saying something like "Cannot find data with given rowKey:6". The rowKey is indeed correct, so I don't understand what is going wrong here.
Best regards,
Mads
PS: I have simplified the code snippets in an attempt to make my problem more clear. Please bear over with me, if I have introduced any typos that might be disturbing to the reader...