-
1. Re: CDI RequestContext not keeping the lazydatamodel's value in primefaces3.2
jf321023 Aug 12, 2012 6:48 AM (in response to jf321023)I found a method to solve this problem. But just for LazyDataModel , I do not know is where any other component will have this problem ,too.
I override the LazyDataModel , in my lazydatamodel i put this page data in the viewmap. and then get it out.
public abstract class LazyDataTableModel<T> extends LazyDataModel<T> implements
SelectableDataModel<T>, Serializable {
private List<T> datasource;
private String clientId;
public LazyDataTableModel() {
this.setPageSize(10);
clientId = FacesContext.getCurrentInstance().getViewRoot().getClientId();
}
@Override
public T getRowData(String rowKey) {
datasource = (List<T>) FacesContext.getCurrentInstance().getViewRoot().getViewMap().get(clientId+"_datatable");
for (T t : datasource) {
if (String.valueOf(datasource.indexOf(t)).equals(rowKey))
return t;
}
return null;
}
@Override
public Object getRowKey(T t) {
return String.valueOf(datasource.indexOf(t));
}
@Override
public List<T> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, String> filters) {
datasource = lazyLoad(first, pageSize);
FacesContext.getCurrentInstance().getViewRoot().getViewMap().put(clientId+"_datatable", datasource);
return datasource;
}
public List<T> lazyLoad(int first, int pageSize){
return null;
}
@Override
public void setRowIndex(int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
} else
super.setRowIndex(rowIndex % getPageSize());
}
}