I'm pretty new to PrimeFaces, I used Richfaces before, but it has changed the wrong way with the release of 4.0.
So I would like to achieve following work logic with datatable:
1.) if the user double clicks on a row, it should open up a different form editing the clicked row content
2.) if the user clicks with right-mouse button, a context menu should appear with multiple choices to open different other forms from the selected line data
So I used the dblClickSelects="true" tag in the definition, and it works for double clicking selection. However not perfect. First I do not have a method bindig or method expression for double click selection, only the p:ajax event="rowSelect" wich behaves quite interesting as the listener wich is called does not reflect the current value, but the previous selected row value. Second if I click with the right mouse button, the same p:ajax event is launched, so a row selection occures again, so it is not good to make the processing on the p:ajax listener.
How can such a logic be made?
datatable definition:
Code: Select all
<p:dataTable resizableColumns="true" scrollable="true" selection="#{viewBean.selectedRows}" selectionMode="single" rowKey="#{result[6]}"
scrollHeight="400" id="datatable" value="#{viewBean.result}"
var="result">
<f:facet name="header">
<h:outputText value="" id="header_text" />
</f:facet>
<p:ajax event="rowSelect" listener="#{viewBean.rowSelectedAction}"></p:ajax>
</p:dataTable>
<p:contextMenu for="datatable" id="contextMenu">
</p:contextMenu>
viewBean:
Code: Select all
@ManagedBean(name = "viewBean")
@ViewScoped
public class View implements Serializable
..
private Object[] selectedRows;
public Object[] getSelectedRows() {
return selectedRows;
}
public void setSelectedRows(Object[] selectedRows) {
this.selectedRows = selectedRows;
}
public String rowSelectedAction()
{
System.out.println("Row selected: " + selectedRows); // at the first selection this is always NULL !!!!, then with every selection it contains the previous value!
if (selectedRows instanceof Object[])
{
System.out.println("value: " + ((Object[]) selectedRows)[0]);
}
else if (selectedRows instanceof Object)
{
System.out.println("value: " + selectedRows);
}
return null;
}
Regards,
byr
PS: keep up the good work