Reputation: 381
I want to retain the value of previously selected row index to compare it with the currently selected rown index.How can I able to get the previous index in backing bean from a datatable in jsf ? Here is the sample code for getting the current index from datatable.
public void setindexvalue(DateSelectEvent event) {
int index = Integer.parseInt(((String) event.getComponent()
.getAttributes().get("index")).replace("_", ""));
System.out.println("Index:\t" + index);
}
I am calling the above method in JSF XHTML using the below code :
<p:ajax event="dateSelect" listener="#{Bean.setindexvalue}" />
<f:attribute name="index" value="_#{rowIndex}" />
The above code is inside a datatable for a specific cell and I want to call the "setindexvalue" each time when a row gets selected, but when I click the next row somehow,I want to retain the value of previously selected row index in backing bean.So that I can compare the current index with the previous index
How can I able to do it ?
Upvotes: 0
Views: 1117
Reputation: 380
private int previous_index;
public void setindexvalue(DateSelectEvent event) {
int index = Integer.parseInt(((String) event.getComponent()
.getAttributes().get("index")).replace("_", ""));
System.out.println("Index:\t" + index);
// Here you have your previous index stored in the variable and can do the comparison
previous_index = index;
}
Upvotes: 2