Initialize a list in my bean with only one record?

0

Good afternoon, my query is the following one I have a bean that initializes me in its method three lists.

 @PostConstruct
 public void inicializarBean() {

    ordenTrabajoRemisionList = ordentrabajoRemisionFacade.findAll();
    ordenTrabajoList = ordentrabajoFacade.findAll();
    tipoRemisionList = tipoRemisionFacade.findAll();       


    tipoRemisionSeleccionada = new TipoRemision();
    ordentrabajoRemision = new OrdentrabajoRemision();
    productoRemision = new ProductoRemision();
    materialRemision = new MaterialRemision();
    ordentrabajo = new Ordentrabajo();

    fechaActual = Calendar.getInstance().getTime();

}

these lists are shown in a datatable and filtered by any column, the question is how to initialize the list without throwing all the records in the datatable if you can not filter them in the ID column and ask me the query specify and throw me a single row.

    
asked by Alexander Gil Tafur 17.07.2017 в 19:57
source

1 answer

0

The problem is not with JSF, but with how you initialize the list. Apparently, you are using the findAll method of your facades, so it is understood that you are recovering all the elements of your entity or table. What you must do is create a new method that allows you to bring the results by pages, that is, bring only a part of all the components that you should bring, and use that to show on your first page.

Example:

public class OrdenTrabajoRemisionFacade {
    public List<OrdenTrabajoRemission> findPage(int offset, int limit) {
        //implementación que dependerá de cómo obtienes los datos desde bd
    }
}

//...

@PostConstruct
public void inicializarBean() {
    //ejemplo
    ordenTrabajoRemisionList = ordentrabajoRemisionFacade.findPage(0, 10);
    //hacer algo similar para tu caso
    ordenTrabajoList = ordentrabajoFacade.findAll();
    tipoRemisionList = tipoRemisionFacade.findAll();       

    tipoRemisionSeleccionada = new TipoRemision();
    ordentrabajoRemision = new OrdentrabajoRemision();
    productoRemision = new ProductoRemision();
    materialRemision = new MaterialRemision();
    ordentrabajo = new Ordentrabajo();

    fechaActual = new Date(); //Calendar.getInstance().getTime();
}

One suggestion of mine, you can bring more results through an ajax event to give the notion that there are more results. This with JSF alone can not be achieved (so easily), it would be best to use a library like Omnifaces and or lazy loading from PrimeFaces .

    
answered by 22.07.2017 в 18:32