Search code examples
jsf-2primefaces

Prime Faces Collector Adding in the reverse order


I am using prime faces collector component and when the user is adding an item to the list, it is adding the record to the end of the list. Is there any easy way of adding the item to the top of the list?


Solution

  • you can simply reverse a list in java itself like this.

    XHTML

    <p:collector value="#{createBookBean.book}"   
                            addTo="#{createBookBean.books}" />  
    

    MANAGED BEAN

       private List<Book> books = new ArrayList<Book>(); 
    
        public List<Book> getBooks() {
               **Collections.reverse(this.books);**
        return books;
    }
    
    public void setBooks(List<Book> books) {
        this.books = books;
    }