5 Replies Latest reply on Aug 22, 2012 4:08 AM by sabarinathsss

    Server side pagination(using richfaces 4.2.2)

    sabarinathsss

      i m override the methods present in the ExtendedDataModel to do true pagination(server side pagination).

       

      Code(PaginationDataModel) :

       

      import java.io.Serializable;
      import java.util.ArrayList;
      import javax.faces.context.FacesContext;
      import org.ajax4jsf.model.DataVisitor;
      import org.ajax4jsf.model.ExtendedDataModel;
      import org.ajax4jsf.model.Range;
      import org.ajax4jsf.model.SequenceRange;
      import org.jboss.logging.Logger;

      public class PaginationDataModel extends ExtendedDataModel<HashMap> implements Serializable  {

       

      private static final long serialVersionUID = 1L;

          ArrayList<HashMap> mDataList = new ArrayList<HashMap>();
          HashMap mAnswerMap;
          private Integer mRowKey;
        
          public PaginationDataModel(HashMap answerMap) { 
           super();
           mAnswerMap=answerMap;
          }

          @Override
          public void setRowKey(Object o) {
              mRowKey = (Integer) o;
          }

       

          @Override
          public Object getRowKey() {
              return mRowKey;
          }
         

      @Override
      public HashMap getRowData() {
        return mDataList.get(mRowKey);
      }

       

      @Override
      public int getRowIndex() {
          return -1;
      }

      @Override
      public Object getWrappedData() {
        throw new UnsupportedOperationException();
      }

      @Override
      public boolean isRowAvailable() {
         return mRowKey != null;
      }

      @Override
      public void setRowIndex(int arg0) {
        throw new UnsupportedOperationException();
       
      }

      @Override
      public void setWrappedData(Object arg0) {
        throw new UnsupportedOperationException();
      }

      @Override
      public int getRowCount() {
       
       
        String getListCountUrl = mAnswerMap.get("Object::Count::Url").toString();
        org.jboss.resteasy.client.ClientRequest clientRequest = new org.jboss.resteasy.client.ClientRequest(getListCountUrl);
        org.jboss.resteasy.client.ClientResponse<DataDetail> clientResponse = null;
        try {
         clientResponse = clientRequest.get(DataDetail.class);
        } catch (Exception exception) {
        
        }
       
        mLog.debug(mClassName+ " :: "+methodName+" :: Exited ");
        return  clientResponse.getEntity(int.class);
       
      }


      @Override
      public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
            
        final StringBuffer methodName = new StringBuffer("walk");
        mLog.debug(mClassName+ " :: "+methodName+" :: Entered ");
       
        SequenceRange sequenceRange = (SequenceRange) range;
        try{
         if (sequenceRange.getFirstRow() >= 0 && sequenceRange.getRows() > 0) {
         
          String getListUrl = mAnswerMap.get("Object::DataList::Url")+"&startplace="+sequenceRange.getFirstRow()+"&range="+sequenceRange.getRows();
          org.jboss.resteasy.client.ClientRequest clientRequest = new org.jboss.resteasy.client.ClientRequest(getListUrl);
            org.jboss.resteasy.client.ClientResponse<DataDetail> clientResponse = null;
          clientResponse = clientRequest.get(DataDetail.class);
          mDataList=clientResponse.getEntity(DataDetail.class).getDataList();
         }

         for(int index = 0; index < mDataList.size(); index++) {
          visitor.process(context,index, argument);
         }
        }catch (Exception exception) {
        
        }
      }


      }

       

      ManagedBean(in ViewScope) :

       

       

      public void getSampleList(String param1,long param2) throws Exception

      {

       

        org.jboss.resteasy.client.ClientRequest clientRequest;

        QuestionHashMap answerMap=new QuestionHashMap();

       

        try{

        

         String sampleUrl=constants.getValueOf("sampleUrl");

         String sampleUrl1=constants.getValueOf("sampleUrl1");

         clientRequest = new org.jboss.resteasy.client.ClientRequest(sampleUrl);

         clientRequest.queryParameter("param2", param2);

         clientRequest.queryParameter("param1", param1);

         answerMap.put("Object::DataList::Url",clientRequest.getUri());

         clientRequest=new org.jboss.resteasy.client.ClientRequest(sampleUrl11);

         clientRequest.queryParameter("param2", param2);

         clientRequest.queryParameter("param1", param1);

         answerMap.put("Object::Count::Url",clientRequest.getUri());

         mDataModel=new PaginationDataModel(answerMap);

         this.setDataModel(mDataModel);

              

        }catch (Exception exception) {

        

        

        }

       

      }

       

       

       

      Here the getRowCount() and walk() method is called more number of times.

       

      In which order or how the methods [setRowKey,getRowKey,walk,isRowAvailable,getRowCount,getRowData,getRowIndex,setRowIndex ]

      are executed?

       

      Why the getRowCount() and walk() called more number of times?(in my case walk method called 3 times,getRowCount() method called 8 times)

       

      Thanks ,

      Sabarinath.