1 Reply Latest reply on Aug 12, 2012 6:48 AM by Feng Jiang

    CDI RequestContext not keeping the lazydatamodel's value in primefaces3.2

    Feng Jiang Newbie

      Hi,everyone:

       

           I am using primefaces3.2 in seam3.1.Final. But when i use the Primefaces's DataTable component. i found the mothed getWrappeData() of LazyDataModel always return null in the CDI 's requestcontext.  If i changed to cdi's SessionScoped or JSF's ViewScoped , it will be fine.   Becouse i want to get the selected rows of the datatable. How to solve this problem? i need help ~~

       

           Or can i use the ViewScoped instand of CDI's RequestScoped ? will it has some effect of cdi using?

       

          In our application, mostly we want to edit some objects while staying in the same page. Is it a issue in primefaces3.2 or cdi?

        • 1. Re: CDI RequestContext not keeping the lazydatamodel's value in primefaces3.2
          Feng Jiang Newbie

          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());

                    }

          }