I am using an in rowselection mode and trying just to get the selected row of the datatable.
I have tried it using the stateMap of IceFaces, but it does not work. The ajax event opens a dialog after selection, where I want to show data of the selected row.
<ace:dataTable id="datatable"
value="#{myBean.myValues()}"
var="myValue" paginator="true" paginatorPosition="bottom"
selectionMode="single" rows="15" rowKey="#{myValue.id}"
doubleClickSelect="true">
<ace:ajax event="select" render="#this" execute="#this"
onStart="ice.ace.instance('#{myDialog.clientId}').show();" />
...
You can add rowSelectListener to the tag <ace:dataTable>
<ace:dataTable rowSelectListener="#{manageBean.rowSelectListener1}" >
And add a function in the code behind to get the row selected.
public void rowSelectListener1(SelectEvent event){
DataType selectedItem = (DataType )event.getObject();
}
Related
I got the following problem using Primefaces 5.2 and JSF 2.1
I got a p:dataTable, and when the user selects a row, the selected object's data should be shown below the table. One requirement is that there should be a checkbox below the table, which should be editable. If the user toggles the checkbox and selects a different entry in the table, the checkbox' new value should be saved. (see the code below)
But I observed the following behaviour. When I select object1, check its checkbox and then select object2, object2's setter will be called, not object1's. Thus object2.someValue will be changed, while object1.someValue won't be. any idea?
<p:dataTable var="myVar" selectionMode="single"
id="myTable" selection="#{form.myValue}"
rowKey="#{myVar.id}"
value="#{form.myTableData}">
<!-- columns here -->
<p:ajax event="rowSelect" process="my_booleancheckbox" update="wrapper">
<p:dataTable>
<h:panelGroup id="wrapper">
<p:booleanCheckbox value="#{form.myValue.someValue}" id="my_booleancheckbox"/>
<!--other stuff here -->
</h:panelGroup>
That's how it is supposed to work, the rowSelect event is fired after the property selection of your p:dataTable is updated
move your ajax action to the p:booleanCheckbox
<p:dataTable var="myVar" selectionMode="single"
id="myTable" selection="#{form.myValue}"
rowKey="#{myVar.id}"
value="#{form.myTableData}">
<!-- columns here -->
<p:dataTable>
<h:panelGroup id="wrapper">
<p:booleanCheckbox value="#{form.myValue.someValue}" id="my_booleancheckbox">
<p:ajax process="my_booleancheckbox" update="wrapper">
</p:booleanCheckbox>
<!--other stuff here -->
</h:panelGroup>
What i want to do is; when user clicks to row, it will select the row.When user double clicks to row, it will start cell editing. At Primefaces showcase(http://www.primefaces.org/showcase/ui/d ... nstant.jsf) it says "Instant row selection, dblclick selection and unselection is implemented using ajax behaviors." but i couldnt find where they implemented dblclick selection. Is there a way to start cell editing event with double click event?
<p:ajax event="rowDblselect">
From PrimeFaces Users Guide
Use
<p:ajax event="rowDblselect" />
in your <p:dataTable /> like this:
<p:dataTable
id="yourTableId"
value="#{yourBean.items}"
selectionMode="single"
selection="#{yourBean.selectedItem}"
var="item"
rowKey="#{item.id}">
<p:ajax
event="rowDblselect"
listener="#{yourBean.onRowDoubleClick}"
update="#form:theComponentYouWantToUpdate"
global="false" />
<!-- your columns here -->
</p:dataTable>
In your bean/controller use:
import org.primefaces.event.SelectEvent;
public void onRowDoubleClick(final SelectEvent event) {
YourObject obj = (YourObject) event.getObject();
// rest of your logic
}
Try setting dblClickSelect="true" on your table.
From the documentation:
By default, row based selection is enabled by click event, enable dblClickSelect so that clicking double on a row does the selection.
I want to get the selected row of my dataTable, directly if the user selects a row.
I have added
<p:dataTable id="dataTableID" var="row"
value="#{bean.value}"
rowKey="${row.id}"
selection="#{bean.selectedValue}" selectionMode="single">
It is just possible to get it after clicking on a button.
There are two ajax-events for instant row selection in primefaces dataTable. One for the selection and one for the unselection.
<p:dataTable ..>
<p:ajax event="rowSelect" listener="#{yourBean.someListener}"/>
...
</p:dataTable>
Now you can access the selected item (of class Foo) like this:
public void someListener(SelectEvent event) {
(Foo) event.getObject() // cast "Object" to "Foo"
}
For additional information take a look at the primefaces showcase first: http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf
I have a primefaces datatable and inside the primefaces datatable, I have a column, which contains the . The issue is,I have set the default value for the as false. When I click/check the , its still retrieving the value as false. I tried it multiple times but not sure why its returning false. Please find the sample code below.
<p:dataTable id="review-table" var="item" value="#{demandBean.filterVOList}">
<p:column id="SelectallID" style="text-align: left; width:40px;" rendered="#{demandBean.screeRenderVo.selectAllRenderer}">
<f:facet name="header" >
<h:outputText id="selectId" value="#{demandBean.dmdScreenLabelVO.selectAll}" />
<div></div>
<h:selectBooleanCheckbox id="checkbox1" value="Select All" onclick="checkAll(this)"/>
</f:facet>
<h:selectBooleanCheckbox id="checkbox2" value="#{item.selected}"/>
</p:column>
Im getting the value as false, when I check the and click on the save button. I have written an Action listerner, below is the code corresponding to the actionListener
public void saveData(ActionEvent event)
{
System.out.println("Entering the Save :");
selected = isSelected();
System.out.println("value of Selected"+selected);
}
I have tried debugging the code as well, but not sure why the value for is getting displayed as false. Please Assist. Thanks in Advance
You seem to be binding the value of all checkboxes in the column to the one and same bean property. This way the value will ultimately end up to be the one of the last row in the column.
This is not how it's supposed to be used.
You basically need to bind the value of the checkbox to the property of the currently iterated row object (the one behind the var attribute of the datatable).
<p:dataTable value="#{bean.items}" var="item">
<p:column>
<p:selectBooleanCheckbox value="#{item.selected}" />
Alternatively, you could use the <p:column selectionMode="multiple" /> to use builtin multiple selection support of the PrimeFaces datatable (see also the showcase example).
<p:dataTable value="#{bean.items}" var="item" rowKey="#{item.id}" selection="#{bean.selectedItems}">
<p:column selectionMode="multiple" />
I use primefaces 3.0.1 and I have a problem with my datatable.
I use my datatable with the instant row selection. That works very well.
But I wish use in the same time the checkbox selection (for exemple, for select some rows and delete the selected rows)
And when I use the
<p:column selectionMode="multiple" />
the checkbox are display, but I can't check any checkbox....
Anyone have a solution ?
Thanks.
P.S. :
my code
<p:dataTable id="rows" var="row" value="#{myBean.row}" selection="#{myBean.selectedRow}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{myBean.onRowSelect}" update="#form"/>
<p:column selectionMode="multiple" style="width:18px" />
<p:column>
<h:outputText value="#{row.subject}" />
</p:column>
</p:dataTable>
Checkboxes are to be used for multiple row selection, but you've still declared your <p:dataTable> for single row selection. Remove selectionMode="single" from the <p:dataTable> and make sure that the #{myBean.selectedRow} is changed to be an array instead.
E.g.
<p:dataTable ... selection="#{myBean.selectedRows}">
with
private Row[] selectedRows;