1 2 Previous Next 25 Replies Latest reply on May 26, 2009 9:42 AM by hai yenbai

    datascoller on page number click data disappears

    Mahesh Shinde Newbie

      Hi,

      I am using RichFaces version 3.3.0 ,

      In my JSF page I have used <rich:datascroller > Initially it shows the pagination below the table but when I click on any of the page number all data disappears.

      <rich:datascroller pageIndexVar="pageIndex" pagesVar="pages"
      id="datascroller" maxPages="10" renderIfSinglePage="false"
      for="transportData" >
      </rich:datascroller>
      


      If someone knows why it is happening then please guide me.

      Regards
      Mahesh

        • 1. Re: datascoller on page number click data disappears
          Nick Belaevski Master

          Hello Mahesh,

          Looks like after page switching model changes to a single-paged set of data, that's why data scroller component disappeared. Are you using custom data model?

          • 2. Re: datascoller on page number click data disappears
            Mahesh Shinde Newbie

            Yes , I am using TransportSummary Object to display data by using <rich:datatable>
            Below is detail code

            <rich:dataTable id="transportData"
            value="#{browserAction.transportList}" var="transport" rows="5">
            <rich:column id="transportNo">
             <f:facet name="header">
             <h:outputText value="TransportNo"></h:outputText>
             </f:facet>
             <h:outputText value="#{transport.transportNo}" />
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <h:outputText value="Container No"></h:outputText>
             </f:facet>
             <h:outputText value="#{transport.containerNo}" />
             </rich:column>
             <rich:column>
             <f:facet name="header">
             <h:outputText value="Document No"></h:outputText>
             </f:facet>
             <h:outputText value="#{transport.documentNo}" />
             </rich:column>
             </rich:dataTable>
             <rich:datascroller id="datascroller" maxPages="10" for="transportData"/>
            

            #{browserAction.transportList} - returns the list of 'TransportSummary' objects.

            Regards
            Mahesh



            • 3. Re: datascoller on page number click data disappears
              Nick Belaevski Master

              I still cannot reproduce the issue. Please post "browserAction" bean code.

              • 4. Re: datascoller on page number click data disappears
                Mahesh Shinde Newbie

                Hi,

                Below is BrowserAction

                
                package com.dss.action;
                
                import java.util.List;
                
                import javax.faces.context.FacesContext;
                import javax.servlet.http.HttpServletRequest;
                
                import com.dss.delegate.LogisticsDelegator;
                import com.otto.b2b.logistics.utils.models.SearchCriteria;
                import com.otto.b2b.logistics.utils.models.TransportSummary;
                
                public class BrowserAction {
                
                 private SearchCriteria searchCriteria;
                 private List<TransportSummary> transportList;
                
                 public void action() {
                 transportList = LogisticsDelegator.getInstance().getBrowserService().getTransportOverViewList(
                 null, getSearchCriteria(), null, Long.valueOf(536350), false);
                 }
                
                
                 /**
                 * Gets the value of searchCriteria property.
                 *
                 * @return searchCriteria - represents searchCriteria
                 */
                 public SearchCriteria getSearchCriteria() {
                 HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance()
                 .getExternalContext().getRequest();
                 searchCriteria = (SearchCriteria) request.getAttribute("searchCriteria");
                 searchCriteria.setLanguageId(Long.valueOf(3064863));
                 return searchCriteria;
                 }
                
                
                 /**
                 * Gets the value of transportList property.
                 * @return transportList - represents transportList
                 */
                 public List<TransportSummary> getTransportList() {
                 return transportList;
                 }
                }


                • 5. Re: datascoller on page number click data disappears
                  Nick Belaevski Master

                  Please tell also what is the scope of BrowserAction bean?

                  • 6. Re: datascoller on page number click data disappears
                    Eugene Kisly Newbie

                     

                    "nbelaevski" wrote:
                    Hello Mahesh,

                    Looks like after page switching model changes to a single-paged set of data, that's why data scroller component disappeared. Are you using custom data model?


                    Hello, i have the same problem, and i use custom data model:

                    package com.cs.cbc.web.action;
                    
                    import com.cs.cbc.bl.entity.audit.AuthenticationAudit;
                    import com.cs.cbc.integration.Message;
                    import com.cs.sessionfacade.remote.SessionFacade;
                    import org.ajax4jsf.model.DataVisitor;
                    import org.ajax4jsf.model.Range;
                    import org.ajax4jsf.model.SequenceRange;
                    import org.ajax4jsf.model.ExtendedDataModel;
                    import org.apache.log4j.Logger;
                    import org.richfaces.model.ScrollableTableDataModel;
                    import org.richfaces.model.SortOrder;
                    import org.richfaces.model.Ordering;
                    
                    import javax.faces.context.FacesContext;
                    import java.io.IOException;
                    import java.util.*;
                    
                    /**
                     * @author ias
                     * This is example class that intended to demonstrate use of ExtendedDataModel and SerializableDataModel.
                     * This implementation intended to be used as a request scope bean. However, it actually provides serialized
                     * state, so on a post-back we do not load data from the data provider. Instead we use data that was used
                     * during rendering.
                     * This data model must be used together with Data Provider, which is responsible for actual data load
                     * from the database using specific filtering and sorting. Normally Data Provider must be in either session, or conversation
                     * scope.
                     */
                    public class AuthenticationAuditDataModel extends ExtendedDataModel {
                    
                     //TODO normal sort data
                    
                     private static final Logger logger = Logger.getLogger(AuthenticationAuditDataModel.class);
                    
                     private SessionFacade sessionFacade;
                     private Long currentPk;
                     private Map<Long, AuthenticationAudit> wrappedData = new HashMap<Long, AuthenticationAudit>();
                     private List<Long> wrappedKeys = null;
                     private final int rowsPerPage = 10;
                    
                     private int page;
                    
                     private Ordering regdateOrdering = Ordering.UNSORTED;
                     private Ordering loginOrdering = Ordering.UNSORTED;
                     private Ordering roleOrdering = Ordering.UNSORTED;
                     private Ordering successOrdering = Ordering.UNSORTED;
                     private Ordering reasonOrdering = Ordering.UNSORTED;
                    
                     private String regdateSort;
                     private String logineSort;
                     private String roleSort;
                     private String successSort;
                     private String reasonSort;
                    
                     /**
                     *
                     */
                     private static final long serialVersionUID = -1956179896877538628L;
                    
                     /**
                     * This method never called from framework.
                     * (non-Javadoc)
                     *
                     * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
                     */
                     @Override
                     public Object getRowKey() {
                     return currentPk;
                     }
                    
                     /**
                     * This method normally called by Visitor before request Data Row.
                     */
                     @Override
                     public void setRowKey(Object key) {
                     this.currentPk = (Long) key;
                    
                     }
                    
                     /**
                     * This is main part of Visitor pattern. Method called by framework many times during request processing.
                     */
                     @Override
                     public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) throws IOException {
                     int firstRow = ((SequenceRange) range).getFirstRow();
                     int numberOfRows = ((SequenceRange) range).getRows();
                     logger.debug("============walk begin===================");
                     logger.debug("firstRow: " + firstRow + ", numberOfRows: " + numberOfRows);
                    
                     if (numberOfRows == -1) {
                     numberOfRows = rowsPerPage;
                     }
                    
                     wrappedKeys = new ArrayList<Long>();
                    
                     logger.debug("regdateOrdering: " + regdateOrdering);
                     logger.debug("loginOrdering: " + loginOrdering);
                     logger.debug("roleOrdering: " + roleOrdering);
                     logger.debug("successOrdering: " + successOrdering);
                     logger.debug("reasonOrdering: " + reasonOrdering);
                    
                    
                    
                     Message message = new Message();
                     message.getBody().add("firstRow", firstRow);
                     message.getBody().add("numberOfRows", numberOfRows);
                    
                     Message resultMessage = sessionFacade.getAuthenticationAudits(message);
                    
                     rowCount = (Integer) resultMessage.getBody().get("rowCountSize");
                     List<AuthenticationAudit> authenticationList = (List<AuthenticationAudit>) resultMessage.getBody().get("audits");
                    
                    
                     logger.debug("fullsize: " + rowCount);
                     logger.debug("authenticationList size: " + authenticationList.size());
                     Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
                     Set<Map.Entry<String, String>> requestSet = requestMap.entrySet();
                     for (Map.Entry<String, String> entry : requestSet) {
                     logger.debug("entry key: " + entry.getKey() + ", entry value: " + entry.getValue());
                     }
                     logger.debug("============walk end=====================");
                    
                     for (AuthenticationAudit item : authenticationList) {
                     wrappedKeys.add(item.getId());
                     wrappedData.put(item.getId(), item);
                     visitor.process(context, item.getId(), argument);
                     }
                     }
                    
                     /**
                     * This method must return actual data rows count from the Data Provider. It is used by pagination control
                     * to determine total number of data items.
                     */
                     private Integer rowCount; // better to buffer row count locally
                    
                     @Override
                     public int getRowCount() {
                     if (rowCount == null) {
                     rowCount = (Integer) sessionFacade.getAuthenticationRowCount(new Message()).getBody().get();
                     return rowCount;
                     } else {
                     return rowCount;
                     }
                     }
                    
                     /**
                     * This is main way to obtain data row. It is intensively used by framework.
                     * We strongly recommend use of local cache in that method.
                     */
                     @Override
                     public Object getRowData() {
                     if (currentPk == null) {
                     return null;
                     } else {
                     AuthenticationAudit ret = wrappedData.get(currentPk);
                     if (ret == null) {
                     Message message = new Message();
                     message.getBody().add(currentPk);
                     ret = (AuthenticationAudit) sessionFacade.getAuthenticationById(message).getBody().get();
                     wrappedData.put(currentPk, ret);
                     return ret;
                     } else {
                     return ret;
                     }
                     }
                     }
                    
                     /**
                     * Unused rudiment from old JSF staff.
                     */
                     @Override
                     public int getRowIndex() {
                     throw new UnsupportedOperationException();
                     }
                    
                     /**
                     * Unused rudiment from old JSF staff.
                     */
                     @Override
                     public Object getWrappedData() {
                     throw new UnsupportedOperationException();
                     }
                    
                     /**
                     * Never called by framework.
                     */
                     @Override
                     public boolean isRowAvailable() {
                     if (currentPk == null) {
                     return false;
                     } else {
                     Message message = new Message();
                     message.getBody().add(currentPk);
                     return (sessionFacade.getAuthenticationById(message).getBody().get() != null);
                     }
                     }
                    
                     /**
                     * Unused rudiment from old JSF staff.
                     */
                     @Override
                     public void setRowIndex(int rowIndex) {
                     throw new UnsupportedOperationException();
                     }
                    
                     /**
                     * Unused rudiment from old JSF staff.
                     */
                     @Override
                     public void setWrappedData(Object data) {
                     throw new UnsupportedOperationException();
                     }
                    
                    
                     public SessionFacade getSessionFacade() {
                     return sessionFacade;
                     }
                    
                     public void setSessionFacade(SessionFacade sessionFacade) {
                     this.sessionFacade = sessionFacade;
                     }
                    
                     public int getRowsPerPage() {
                     return rowsPerPage;
                     }
                    
                     public Long getCurrentPk() {
                     return currentPk;
                     }
                    
                     public void setCurrentPk(Long currentPk) {
                     this.currentPk = currentPk;
                     }
                    
                     public List<Long> getWrappedKeys() {
                     return wrappedKeys;
                     }
                    
                     public void setWrappedKeys(List<Long> wrappedKeys) {
                     this.wrappedKeys = wrappedKeys;
                     }
                    
                     public Ordering getRegdateOrdering() {
                     return regdateOrdering;
                     }
                    
                     public void setRegdateOrdering(Ordering regdateOrdering) {
                     logger.debug("regdateOrdering: " + regdateOrdering);
                     this.regdateOrdering = regdateOrdering;
                     }
                    
                     public Ordering getLoginOrdering() {
                     return loginOrdering;
                     }
                    
                     public void setLoginOrdering(Ordering loginOrdering) {
                     logger.debug("loginOrdering: " + loginOrdering);
                     this.loginOrdering = loginOrdering;
                     }
                    
                     public Ordering getRoleOrdering() {
                     return roleOrdering;
                     }
                    
                     public void setRoleOrdering(Ordering roleOrdering) {
                     this.roleOrdering = roleOrdering;
                     }
                    
                     public Ordering getSuccessOrdering() {
                     return successOrdering;
                     }
                    
                     public void setSuccessOrdering(Ordering successOrdering) {
                     this.successOrdering = successOrdering;
                     }
                    
                     public Ordering getReasonOrdering() {
                     return reasonOrdering;
                     }
                    
                     public void setReasonOrdering(Ordering reasonOrdering) {
                     this.reasonOrdering = reasonOrdering;
                     }
                    
                     public String getRegdateSort() {
                     return regdateSort;
                     }
                    
                     public void setRegdateSort(String regdateSort) {
                     logger.debug("regdatasoft: " + regdateSort);
                     this.regdateSort = regdateSort;
                     }
                    
                     public String getLogineSort() {
                     return logineSort;
                     }
                    
                     public void setLogineSort(String logineSort) {
                     logger.debug("logineSort: " + regdateSort);
                     this.logineSort = logineSort;
                     }
                    
                     public String getRoleSort() {
                     return roleSort;
                     }
                    
                     public void setRoleSort(String roleSort) {
                     this.roleSort = roleSort;
                     }
                    
                     public String getSuccessSort() {
                     return successSort;
                     }
                    
                     public void setSuccessSort(String successSort) {
                     this.successSort = successSort;
                     }
                    
                     public String getReasonSort() {
                     return reasonSort;
                     }
                    
                     public void setReasonSort(String reasonSort) {
                     this.reasonSort = reasonSort;
                     }
                    
                     public int getPage() {
                     return page;
                     }
                    
                     public void setPage(int page) {
                     this.page = page;
                     }
                    }
                    


                    My datascroller hiding when i click on header (try to sort)

                    <h:form id="authenticationForm">
                     <%--binding="#{sessionPageBean.dataTable}"--%>
                    
                     <rich:extendedDataTable value="#{authenticationDataModel}" var="authentication" rows="#{pagination.max}"
                     id="authenticationTable"
                     rowClasses="odd-row, even-row">
                    
                     <rich:column id="regDate" style="min-width: 200px !important;" sortBy="#{authenticationDataModel.regdateSort}" sortOrder="#{authenticationDataModel.regdateOrdering}" sortable="true" selfSorted="true">
                     <f:facet name="header">
                     <h:outputText value="#{bundle.regDate}"/>
                     </f:facet>
                     <h:outputText value="#{authentication.regDate}"/>
                     </rich:column>
                    
                     <rich:column id="loginColumn" style="min-width: 200px !important;" sortBy="#{authenticationDataModel.logineSort}" sortOrder="#{authenticationDataModel.loginOrdering}" sortable="true" selfSorted="true">
                     <f:facet name="header">
                     <h:outputText value="#{bundle.login}"/>
                     </f:facet>
                     <h:outputText value="#{authentication.login}"/>
                     </rich:column>
                    
                     <rich:column id="roleColumn" style="min-width: 200px !important;" sortBy="#{authenticationDataModel.roleSort}" sortOrder="#{authenticationDataModel.roleOrdering}" >
                     <f:facet name="header">
                     <h:outputText value="#{bundle.role}"/>
                     </f:facet>
                     <h:outputText value="#{authentication.role}"/>
                     </rich:column>
                    
                     <rich:column id="reasonColumn" style="min-width: 200px !important;" sortBy="#{authenticationDataModel.reasonSort}" sortOrder="#{authenticationDataModel.reasonOrdering}" >
                     <f:facet name="header">
                     <h:outputText value="#{bundle.reason}"/>
                     </f:facet>
                     <h:outputText value="#{authentication.reason}"/>
                     </rich:column>
                    
                     <rich:column id="successColumn" style="min-width: 200px !important;" sortBy="#{authenticationDataModel.successSort}" sortOrder="#{authenticationDataModel.successOrdering}" >
                     <f:facet name="header">
                     <h:outputText value="#{bundle.success}"/>
                     </f:facet>
                     <h:outputText value="#{authentication.success}"/>
                     </rich:column>
                     <f:facet name="footer">
                     <rich:datascroller ajaxSingle="false" id="authentificationScroll" for="authenticationTable" style="padding-top:10px;"
                     renderIfSinglePage="true" maxPages="10" page="#{authenticationDataModel.page}"/>
                     </f:facet>
                     </rich:extendedDataTable>
                     </h:form>


                    Please help me to solve my problem :)

                    • 7. Re: datascoller on page number click data disappears
                      Nick Belaevski Master

                      LockDog, probably something wrong with rowCount variable.

                      • 8. Re: datascoller on page number click data disappears
                        Mahesh Shinde Newbie

                        scope of the bean is request

                        • 9. Re: datascoller on page number click data disappears
                          Nick Belaevski Master

                          So I think you use different lists (lists of different sizes) on the initial request and on subsequent one. Maybe because

                          request.getAttribute("searchCriteria")
                          has been lost for subsequent requests?

                          • 10. Re: datascoller on page number click data disappears
                            hai yenbai Newbie

                            Hi m.shinde, i have the same problem as you too. I resolved it by way create constructor for my bean to load all data. But i don not like this way because it will hit twice to database and application is very slowly.

                            Hi nbelaevski . Is there other way to resolve this problem ? If i dont use constructor to load all data then when i click page number , action is not active.

                            • 11. Re: datascoller on page number click data disappears
                              Nick Belaevski Master

                              richface_number1,

                              Please post the code.

                              • 12. Re: datascoller on page number click data disappears
                                hai yenbai Newbie

                                MyBean

                                import java.util.ArrayList;
                                import java.util.List;
                                
                                public class MyBean {
                                
                                
                                 String maxId = "";
                                 List classes = new ArrayList() ;
                                 public MyBean(){
                                 //constructor
                                 initData();
                                 }
                                 public void initData(){
                                 // access database
                                 for (int i = 0 ;i< 400 ; i++){
                                 MyClass mc = new MyClass();
                                 mc.setId(""+i);
                                 mc.setClassKind("no kind");
                                 mc.setName("class " + i) ;
                                 classes.add(mc);
                                
                                 }
                                 }
                                 public void actionSearch(){
                                 // access database
                                 ArrayList results = new ArrayList() ;
                                 if (this.getMaxId() != null && this.getMaxId()!= "" ) {
                                 int number = Integer.parseInt(this.getMaxId());
                                 for (int i = 0 ;i< number ; i++){
                                 MyClass mc = new MyClass();
                                 mc.setId(""+i);
                                 mc.setClassKind("no kind");
                                 mc.setName("class " + i) ;
                                 results.add(mc);
                                 }
                                 }
                                 this.setClasses(results);
                                 }
                                
                                 public java.util.List getClasses() {
                                 return classes;
                                 }
                                
                                 public void setClasses(java.util.List classes) {
                                 this.classes = classes;
                                 }
                                 public String getMaxId() {
                                 return maxId;
                                 }
                                 public void setMaxId(String maxId) {
                                 this.maxId = maxId;
                                 }
                                
                                }
                                

                                Model : MyClass

                                public class MyClass {
                                
                                
                                 String name ;
                                 String id;
                                 String classKind;
                                 public String getName() {
                                 return name;
                                 }
                                 public void setName(String name) {
                                 this.name = name;
                                 }
                                 public String getId() {
                                 return id;
                                 }
                                 public void setId(String id) {
                                 this.id = id;
                                 }
                                 public String getClassKind() {
                                 return classKind;
                                 }
                                 public void setClassKind(String classKind) {
                                 this.classKind = classKind;
                                 }
                                
                                }
                                


                                jsp file : findClass.jsp
                                <%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
                                <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                                <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                                <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
                                <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
                                <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
                                <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
                                <LINK HREF="../css/pl.css" TYPE="text/css" REL="stylesheet">
                                
                                <f:view>
                                <f:subview id="body_id">
                                <rich:panel bodyClass="panelClass">
                                
                                <h:form>
                                
                                 <f:facet name="header">
                                 <h:outputText value="Find Class"/>
                                 </f:facet>
                                
                                 <fieldset style="position: relative;left:35%;margin:0px;width: 25%">
                                 <legend >Search</legend>
                                
                                <h:panelGrid columns="2" >
                                
                                <h:column>
                                <h:outputText value="Max Id" styleClass="textBoldClass"/>
                                </h:column>
                                <h:column>
                                <h:inputText value = "#{myBean.maxId}"/>
                                </h:column>
                                <h:column>
                                </h:column>
                                <h:column>
                                <rich:spacer width = "50"></rich:spacer>
                                <h:commandButton value = "Search" styleClass="textBoldClass" action = "#{myBean.actionSearch}"/>
                                </h:column>
                                
                                </h:panelGrid>
                                 </fieldset>
                                
                                
                                <rich:spacer width = "1" height="20"></rich:spacer>
                                
                                <fieldset >
                                 <legend >Data</legend>
                                 <rich:datascroller align="center" for="tableContent_id" immediate="true"/>
                                
                                <rich:dataTable var="classes" value="#{myBean.classes}" id="tableContent_id" width="100%" rowKeyVar="row" rows="20">
                                 <rich:column id="stt_id" >
                                 <f:facet name="header">
                                 <h:outputText value="stt"/>
                                 </f:facet>
                                 <h:outputText value="#{row+1}" />
                                 </rich:column>
                                
                                 <rich:column >
                                 <f:facet name="header">
                                 <h:outputText value="id"/>
                                 </f:facet>
                                 <h:outputText value="#{classes.id}" />
                                 </rich:column>
                                 <rich:column >
                                 <f:facet name="header">
                                 <h:outputText value="name"/>
                                 </f:facet>
                                 <h:outputText value="#{classes.name}" />
                                 </rich:column>
                                 <rich:column >
                                 <f:facet name="header">
                                 <h:outputText value="kind"/>
                                 </f:facet>
                                 <h:outputText value="#{classes.classKind}" />
                                 </rich:column>
                                
                                 </rich:dataTable>
                                </fieldset>
                                
                                </h:form>
                                </rich:panel>
                                
                                
                                </f:subview>
                                
                                </f:view>
                                


                                If i remove contructor of mybean, datascoller is not active.
                                but the datascoller activate wrong when mybean has contructor. I can not see this problem.Please help me .Thank in advance.

                                • 13. Re: datascoller on page number click data disappears
                                  hai yenbai Newbie

                                  I used richfaces 3.3.0.GA , apache tomcat 6.0, firefox 3.0.10 . Is there anybody help me?

                                  • 14. Re: datascoller on page number click data disappears
                                    Nick Belaevski Master

                                    Data scroller component operates with list size only, so there can be several solutions:

                                    1. Develop custom data model (javax.faces.model.DataModel) and override getRowCount() method
                                    2. Return list that will provide data scroller with information about rows count using projection query/cached value

                                    1 2 Previous Next