I am using primefaces v3.5.On the datatable I am using filter on one column. How can I set a default value to the filter while loading the page Itself.
The correct solution is to use the filteredValue attribute of p:dataTable which contains the filtered collection together with filterValue attribute of p:column to show the filters configuration to the user.
To keep your p:dataTable filters stored in your session bean, you have to keep also the filtered data. The p:dataTable wouldn't perform the initial sorting for you.
Check this example JSF:
#{e.user.id}
Backed with this managed bean:
@Named(value = "userListState")
@SessionScoped
public class UserListState implements Serializable{
private Map filterState = new HashMap();
private List filteredValue;
public UserListState() {
}
public void onFilterChange(FilterEvent filterEvent) {
filterState = filterEvent.getFilters();
filteredValue =(List) filterEvent.getData();
}
public String filterState(String column) {
return filterState.get(column);
}
public List getFilteredValue() {
return filteredValue;
}
public void setFilteredValue(List filteredValue) {
this.filteredValue = filteredValue;
}
}