Traverse lines from a javaEE, jsf2, and Primefaces datatable with Keyboard arrows?

Asked

Viewed 90 times

0

I found this code on the Internet, but part of it was discontinued

xhtml:

<p:hotkey bind="down" update=":testform:tabletest" action="#{aBean.moveDown()}" />

aBean:

public void moveDown() {   
  FacesContext facesContext = FacesContext.getCurrentInstance();
  DataTable table = (DataTable)ComponentUtils.findComponent(facesContext.getViewRoot(), "tabletest"); // obtem componente da tabela
  List<City> cl = (List<City>) table.getValue(); // obtem lista de elementos da tabela
  String p_code = selected.getPCode(); // obtém código único do elemento selecionado
  for(int i=0;i<cl.size();i++){ // itera toda a lista de valores
     if(p_code.equalsIgnoreCase(cl.get(i).getPCode())){ // verifica o elemento selecionado é o mesmo da iteração
        if(i==cl.size()-1){
           selected= cl.get(0); // caso seja o último item da lista, mantém ele mesmo selecionado
        }else{
           selected = cl.get(i+1); // caso contrário ele seta a seleção para a linha de baixo
        }
        break;
     }
   }
}
  • selected: Selected line

  • getPCode(): Captures unique value of the list element (some ID for example)

    Someone would have something similar or current?

  • This is a component of the primeFaces ,<p:hotkey bind="down" update=":testform:tabletest" action="#{aBean.moveDown()}" />

1 answer

0

The code misses Asim.

<p:dataTable id="tabelaBancos" paginator="true"
        rowsPerPageTemplate="5,10,15"
        value="#{lancamentoTributoCdgBean.listaBancos}" var="item"
        paginatorPosition="bottom" paginatorAlwaysVisible="flase"
        style="margin-top: 5px;" rows="5">

So that’s how it turned out:

<p:dataTable id="tabelaBancos" scrollable="true" scrollHeight="2500"
		value="#{lancamentoTributoCdgBean.listaBancos}" var="item"
		style="margin-top: 5px;">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.