Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

jsf 2 - Efficient JSF Pagination

Whats the most efficient way of doing pagination in JSF 2.0 app? I use Primefaces datatable and it is intelligent enough to perform pagination by itself with no coding at all.

<p:dataTable var="car" value="#{carBean.cars}" paginator="true" rows="10">
    <!-- Multiple columns here-->
</p:dataTable>

The thing that I see, is that I need to place my bean to session scoped or greater.

@ManagedBean
@SessionScoped
public class CarBean{
    public List<Car> getCars(){
        //return data from DB
    }
}

I wanted to know is there another efficient way on how to perform this?

I used EJB/JPA at the backend by the way. Would like to know any links or tutorials to learn more about this.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use LazyDataModel in order to have only the rows in memory which the client actually needs to see. See also the example in PrimeFaces showcase. This does pagination at DB level which is what you ultimately want.

RichFaces supports by the way the same in flavor of ArrangableDataModel, here's the RichFaces showcase example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...