Datatable row selection by dblClick

UI Components for JSF
Post Reply
byr
Posts: 13
Joined: 28 Oct 2011, 13:51

28 Oct 2011, 14:04

Hi!

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>
The columns are added at runtime dinamically through java code. Also the content of context menu is also dinamically created.

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;
	}
Thanks for help!

Regards,

byr

PS: keep up the good work :)
Jboss AS 7.1.1, JSF 2.1.14, PrimeFaces 3.5 SNAPSHOT

byr
Posts: 13
Joined: 28 Oct 2011, 13:51

31 Oct 2011, 16:31

Hi!

OK, now I can explain more better what my problem is (checked the source for datatable)...

So the dblClickSelects working great. I double click any row, and the rowSelect event is triggered.

The problem is at the context menu right click, as it also runs the same javascript function in the datatable JS wich also triggers the SAME rowSelect event.

So I can not distinguish wether the user double clicket a row, or just opened up the context menu. As in the first case I have to open up the data to edit, in the second case I just wait for the user to select something from the context menu, and then process the users selection.

So how can this be solved? Is this an issue or just a feature request?

Regards,

byr
Jboss AS 7.1.1, JSF 2.1.14, PrimeFaces 3.5 SNAPSHOT

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 59 guests