http://img855.imageshack.us/f/nav.jpg/
The problem that i note i change the value of the cargoSelecionado on managed bean with bindCargo(int index) ,
the datatable don't change the page and rowIndex if i'm on the last row of a page and click next or if i'm on the first row of a page greater than one and i click back button.
( On these cases the page don't change to correct and none row be selected although need ).
Relevant code of xhtml:
Code: Select all
<p:commandButton image="ui-icon ui-icon-circle-arrow-w" title="Next" update="opFormCargos, formCargos, opModoGrade"
action="#{cargoMB.back}" process="@this"/>
<p:commandButton image="ui-icon ui-icon-circle-arrow-e" title="Back" update="opFormCargos, formCargos, opModoGrade"
action="#{cargoMB.next}" process="@this"/>
<p:dataTable id="dataTableCargos"
var="cargo" value="#{cargoMB.cargos}"
paginator="true" dynamic="true"
emptyMessage="Nenhum registro foi encontrado."
rows="10" rowsPerPageTemplate="5,10,15,20"
selection="#{cargoMB.cargoSelecionado}" selectionMode="single"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
onRowSelectUpdate="formCargos, novoCargo" >
Code: Select all
public void next() {
if (cargo != null) {
Integer id = cargo.getId();
if (id == null) {
findData();
if (cargos.size() > 0) {
bindCargo(0);
}
} else {
int idxSelected = getIndexCargoById(id);
if (idxSelected + 1 < cargos.size()) {
bindCargo(idxSelected + 1);
}
}
}
}
public void back() {
if (cargos.size() > 1 && cargo != null) {
Integer id = cargo.getId();
int idxSelected = getIndexCargoById(id);
if (idxSelected > 0) {
bindCargo(idxSelected - 1);
}
}
}
private void bindCargo(int index) {
cargoSelecionado = cargo = cargos.get(index);
}