Reputation: 127
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?
Upvotes: 0
Views: 633
Reputation: 6630
When you add items to binded list you can use .add(0, item)
in your managed bean. It will add desired items at start of the collection.
private List<Item> listItems = new ArrayList<Item>();
public void onAddListItem(){
listItems.add(0, new Item());
}
Upvotes: 1
Reputation: 46418
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;
}
Upvotes: 1