8 Replies Latest reply on Jan 31, 2012 1:48 PM by venuvanama

    Problem with rich:scrollableDataTable

    venuvanama Newbie

      Hi,

       

      I am using rich:scrollableDataTable to display search results. I have set the rows=40, if the query returns more than 40 rows it automatically scrolls to the bottom of the table. How can I set the scroll to the top of the table.

       

      Here is the code I am using to display scrollableDataTable:

       

      <rich:panel id="searchResultPanel" binding="#{deviceMasterFormBean.searchResultPanel}" >

              <f:facet name="header">Device search results (Note:  Double-click results record to view device detail.)</f:facet>       

                  <rich:scrollableDataTable rowKeyVar="rkv" height="400px"

                      width="700px" id="deviceSearchResultsTable" rows="40" columnClasses="col"

                      value="#{deviceMasterFormBean.searchResults}" var="device" sortMode="single"

                       sortOrder="#{deviceMasterFormBean.order}"

                       scrollToTop="true" selection="#{deviceMasterFormBean.selection}" >                      

                      <a4j:support event="onRowDblClick" action="#{deviceTreeBean.onSelectSearchResult}"

                          actionListener="#{deviceTreeBean.onSelectSearchResult}"/>                

                      <rich:column id="tagNumber">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="Tag #" />

                          </f:facet>

                          <h:outputText value="#{device.tagNumber}" />

                      </rich:column>

                      <rich:column id="ip">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="IP" />

                          </f:facet>

                          <h:outputText value="#{device.ip}" />

                      </rich:column>

                      <rich:column id="name">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="Name" />

                          </f:facet>

                          <h:outputText value="#{device.name}" />

                      </rich:column>

                      <rich:column id="domainName">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="Domain" />

                          </f:facet>

                          <h:outputText value="#{device.domainName}" />

                      </rich:column>

                      <rich:column id="namespace">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="Namespace" />

                          </f:facet>

                          <h:outputText value="#{device.namespace}" />

                      </rich:column>

                      <rich:column id="nameType">

                          <f:facet name="header">

                              <h:outputText styleClass="headerText" value="Name Type" />

                          </f:facet>

                          <h:outputText value="#{device.nameType}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedParentName}">

                          <f:facet name="header">

                              <h:outputText value="Parent Name" />

                          </f:facet>

                          <h:outputText value="#{device.parentName}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedParentDomain}">

                          <f:facet name="header">

                              <h:outputText value="Parent Domain" />

                          </f:facet>

                          <h:outputText value="#{device.parentDomain}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedPrimaryName}">

                          <f:facet name="header">

                              <h:outputText value="Primary Name" />

                          </f:facet>

                          <h:outputText value="#{device.primaryName}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedPrimaryDomain}">

                          <f:facet name="header">

                              <h:outputText value="Primary Domain" />

                          </f:facet>

                          <h:outputText value="#{device.primaryDomain}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedBldg}">

                          <f:facet name="header">

                              <h:outputText value="Building" />

                          </f:facet>

                          <h:outputText value="#{device.building}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedFloor}">

                          <f:facet name="header">

                              <h:outputText value="Floor" />

                          </f:facet>

                          <h:outputText value="#{device.floor}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedColBay}" >

                          <f:facet name="header">

                              <h:outputText value="Column/Bay" />

                          </f:facet>

                          <h:outputText value="#{device.colbay}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedCity}">

                          <f:facet name="header">

                              <h:outputText value="City" />

                          </f:facet>

                          <h:outputText value="#{device.city}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedManuf}">

                          <f:facet name="header">

                              <h:outputText value="Manufacturer" />

                          </f:facet>

                          <h:outputText value="#{device.manufacturer}" />

                      </rich:column>                 

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedMac}">

                          <f:facet name="header">

                              <h:outputText value="MAC" />

                          </f:facet>

                          <h:outputText value="#{device.mac}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedAddrBlk}">

                          <f:facet name="header">

                              <h:outputText value="Address Block" />

                          </f:facet>

                          <h:outputText value="#{device.network}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedDeviceType}">

                          <f:facet name="header">

                              <h:outputText value="Device Type" />

                          </f:facet>

                          <h:outputText value="#{device.deviceType}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedStatus}">

                          <f:facet name="header">

                              <h:outputText value="Status" />

                          </f:facet>

                          <h:outputText value="#{device.ipStatus}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedChDate}">

                          <f:facet name="header">

                              <h:outputText value="Change Date" />

                          </f:facet>

                          <h:outputText value="#{device.ipChangeDate}" />

                      </rich:column>

                      <rich:column width="200px" rendered="#{deviceMasterFormBean.selectedLeaseExpire}">

                          <f:facet name="header">

                              <h:outputText value="Lease Expire" />

                          </f:facet>

                          <h:outputText value="#{device.dhcpLease}" />

                      </rich:column>

                  </rich:scrollableDataTable>                    

          </rich:panel>

       

      Thanks for your help.

       

      Venu

        • 1. Re: Problem with rich:scrollableDataTable
          Jorge Campos Newbie

          use the attribute first

           

          cheers

          • 2. Re: Problem with rich:scrollableDataTable
            venuvanama Newbie

            Hi Jorge,

             

            Thanks for your suggestion, I tried setting first="1" but it did not do what I expected, still it scrolled to the bottom of the table. Please let me know if I am not using the first attribute properly,

             

            ~V

            • 3. Re: Problem with rich:scrollableDataTable
              Jorge Campos Newbie

              Hi venuvanama,

               

              which version of richfaces are you using? Because I saw in your code that you are using this attribute "scrollToTop" that doesn't exists on component attributes description as you can see in

              http://livedemo.exadel.com/richfaces-demo/richfaces/scrollableDataTable.jsf?tab=info&cid=297379 at least not in this version that I'm looking.

               

              Maybe this could be causing the problem

               

              and just for test try to use first="0"

               

              let me know what happended!

               

              Best regards,

              Jorge

              • 4. Re: Problem with rich:scrollableDataTable
                venuvanama Newbie

                Hi Jorge,

                 

                We are using RichFaces 3.0, I removed scrollToTop and set first="0". However it did not help. I am wondering if this is a known bug in RichFaces 3.0 and if it is which version would have the fix for this problem.

                 

                Thanks and appreciate your time on this.

                 

                Venu

                • 5. Re: Problem with rich:scrollableDataTable
                  Jorge Campos Newbie

                  Well, I've looked in the Jira database for this component and something related with your issue and I found this:

                  https://issues.jboss.org/browse/RF-2106

                   

                  Maybe you are right some bug related with your version!

                   

                  So, consider update your richfaces version and try again!

                   

                  Jorge.

                  • 6. Re: Problem with rich:scrollableDataTable
                    venuvanama Newbie

                    Thanks Jorge,

                     

                    I will try to update my richfaces version and give it a try, in the meantime if anyone has any idea on how to fix this issue or if you know which version of richfaces fixed this bug I really appreciate any help.

                     

                    Venu

                    • 7. Re: Problem with rich:scrollableDataTable
                      Jorge Campos Newbie

                      Hi Venu,

                       

                      I've implemented the richfaces exadel example and works fine here!

                      I'm using richfaces 3.3.3.final

                       

                      here is the code:

                      MBean:

                       

                      import java.math.BigDecimal;

                      import java.util.ArrayList;

                      import java.util.Arrays;

                      import java.util.List;

                      import java.util.Random;

                       

                         /**

                      * @author Nick Belaevski - nbelaevski@exadel.com

                      * created 02.03.2007

                      *

                      */

                      public class DataTableScrollerBean {

                                private static int DECIMALS = 1;

                                private static int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;

                       

                       

                                private List <DemoInventoryItem> allCars = null;

                       

                       

                                public List <DemoInventoryItem> getAllCars() {

                                          synchronized (this) {

                                                    if (allCars == null) {

                                                              allCars = new ArrayList<DemoInventoryItem>();

                                                              for (int k = 0; k <= 5; k++) {

                                                                        try{

                                                                                  switch (k) {

                                                                                  case 0:

                                                                                            allCars.addAll(createCar("Chevrolet","Corvette", 5));

                                                                                            allCars.addAll(createCar("Chevrolet","Malibu", 8));

                                                                                            allCars.addAll(createCar("Chevrolet","S-10", 10));

                                                                                            allCars.addAll(createCar("Chevrolet","Tahoe", 6));

                                                                                            break;

                       

                       

                                                                                  case 1:

                                                                                            allCars.addAll(createCar("Ford","Taurus", 12));

                                                                                            allCars.addAll(createCar("Ford","Explorer", 11));

                                                                                            break;

                                                                                  case 2:

                                                                                            allCars.addAll(createCar("Nissan","Maxima", 9));

                                                                                            break;

                                                                                  case 3:

                                                                                            allCars.addAll(createCar("Toyota","4-Runner", 7));

                                                                                            allCars.addAll(createCar("Toyota","Camry", 15));

                                                                                            allCars.addAll(createCar("Toyota","Avalon", 13));

                                                                                            break;

                                                                                  case 4:

                                                                                            allCars.addAll(createCar("GMC","Sierra", 8));

                                                                                            allCars.addAll(createCar("GMC","Yukon", 10));

                                                                                            break;

                                                                                  case 5:

                                                                                            allCars.addAll(createCar("Infiniti","G35", 6));

                                                                                            break;

                                                                                  /*case 6:

                                                                                            allCars.addAll(createCar("UAZ","469", 6));

                                                                                            break;*/

                                                                                  default:

                                                                                            break;

                                                                                  }

                                                                        }catch(Exception e){

                                                                                  System.out.println("!!!!!!loadAllCars Error: " + e.getMessage());

                                                                                  e.printStackTrace();

                                                                        }

                                                              }

                                                    }

                                          }

                       

                       

                                          return allCars;

                                }

                       

                       

                                public int genRand() {

                                          return rand(1,10000);

                                }

                       

                       

                                public List <DemoInventoryItem> createCar(String make, String model, int count){

                       

                       

                                          ArrayList <DemoInventoryItem> iiList = null;

                       

                       

                                          try{

                                                    int arrayCount = count;

                       

                       

                                                    DemoInventoryItem[] demoInventoryItemArrays = new DemoInventoryItem[arrayCount];

                       

                       

                                                    for (int j = 0; j < demoInventoryItemArrays.length; j++){

                                                              DemoInventoryItem ii = new DemoInventoryItem();

                       

                       

                                                              ii.setMake(make);

                                                              ii.setModel(model);

                                                              ii.setStock(randomstring(6,7));

                                                              ii.setVin(randomstring(14,15));

                                                              ii.setMileage(new BigDecimal(rand(5000,80000)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setMileageMarket(new BigDecimal(rand(25000,45000)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setPrice(new Integer(rand(15000,55000)));

                                                              ii.setPriceMarket(new BigDecimal(rand(15000,55000)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setDaysLive(rand(1,90));

                                                              ii.setChangeSearches(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setChangePrice(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setExposure(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setActivity(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setPrinted(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              ii.setInquiries(new BigDecimal(rand(0,5)).setScale(DECIMALS, ROUNDING_MODE));

                                                              demoInventoryItemArrays[j] = ii;

                       

                       

                                                    }

                       

                       

                                                    iiList = new ArrayList<DemoInventoryItem>(Arrays.asList(demoInventoryItemArrays));

                       

                       

                                          }catch(Exception e){

                                                    System.out.println("!!!!!!createCategory Error: " + e.getMessage());

                                                    e.printStackTrace();

                                          }

                                          return iiList;

                                }

                       

                       

                                public static int rand(int lo, int hi)

                                {

                                          Random rn2 = new Random();

                                          //System.out.println("**" + lo);

                                          //System.out.println("**" + hi);

                                          int n = hi - lo + 1;

                                          int i = rn2.nextInt() % n;

                                          if (i < 0)

                                                    i = -i;

                                          return lo + i;

                                }

                       

                       

                                public static String randomstring(int lo, int hi)

                                {

                                          int n = rand(lo, hi);

                                          byte b[] = new byte[n];

                                          for (int i = 0; i < n; i++)

                                                    b[i] = (byte)rand('A', 'Z');

                                          return new String(b);

                                }

                      }

                       

                      DataInventoryItem.java

                       

                      import java.math.BigDecimal;

                      import java.io.Serializable;

                       

                       

                      /**

                      * Created by IntelliJ IDEA.

                      * User: Wesley

                      * Date: Jan 26, 2007

                      * Time: 8:21:36 AM

                      * To change this template use File | Settings | File Templates.

                      */

                      public class DemoInventoryItem implements Serializable {

                       

                       

                          String make;

                          String model;

                          String stock;

                          String vin;

                       

                       

                          BigDecimal mileage;

                          BigDecimal mileageMarket;

                          Integer price;

                          BigDecimal priceMarket;

                       

                       

                          int daysLive;

                          BigDecimal changeSearches;

                          BigDecimal changePrice;

                       

                       

                          BigDecimal exposure;

                          BigDecimal activity;

                          BigDecimal printed;

                          BigDecimal inquiries;

                       

                       

                       

                       

                          public String getMake() {

                              return make;

                          }

                       

                       

                          public void setMake(String make) {

                              this.make = make;

                          }

                       

                       

                          public String getModel() {

                              return model;

                          }

                       

                       

                          public void setModel(String model) {

                              this.model = model;

                          }

                       

                       

                          public String getStock() {

                              return stock;

                          }

                       

                       

                          public void setStock(String stock) {

                              this.stock = stock;

                          }

                       

                       

                          public String getVin() {

                              return vin;

                          }

                       

                       

                          public void setVin(String vin) {

                              this.vin = vin;

                          }

                       

                       

                          public BigDecimal getMileage() {

                              return mileage;

                          }

                       

                       

                          public void setMileage(BigDecimal mileage) {

                              this.mileage = mileage;

                          }

                       

                       

                          public BigDecimal getMileageMarket() {

                              return mileageMarket;

                          }

                       

                       

                          public void setMileageMarket(BigDecimal mileageMarket) {

                              this.mileageMarket = mileageMarket;

                          }

                       

                       

                          public Integer getPrice() {

                              return price;

                          }

                       

                       

                          public void setPrice(Integer price) {

                              this.price = price;

                          }

                       

                       

                          public BigDecimal getPriceMarket() {

                              return priceMarket;

                          }

                       

                       

                          public void setPriceMarket(BigDecimal priceMarket) {

                              this.priceMarket = priceMarket;

                          }

                       

                       

                          public int getDaysLive() {

                              return daysLive;

                          }

                       

                       

                          public void setDaysLive(int daysLive) {

                              this.daysLive = daysLive;

                          }

                       

                       

                          public BigDecimal getChangeSearches() {

                              return changeSearches;

                          }

                       

                       

                          public void setChangeSearches(BigDecimal changeSearches) {

                              this.changeSearches = changeSearches;

                          }

                       

                       

                          public BigDecimal getChangePrice() {

                              return changePrice;

                          }

                       

                       

                          public void setChangePrice(BigDecimal changePrice) {

                              this.changePrice = changePrice;

                          }

                       

                       

                          public BigDecimal getExposure() {

                              return exposure;

                          }

                       

                       

                          public void setExposure(BigDecimal exposure) {

                              this.exposure = exposure;

                          }

                       

                       

                          public BigDecimal getActivity() {

                              return activity;

                          }

                       

                       

                          public void setActivity(BigDecimal activity) {

                              this.activity = activity;

                          }

                       

                       

                          public BigDecimal getPrinted() {

                              return printed;

                          }

                       

                       

                          public void setPrinted(BigDecimal printed) {

                              this.printed = printed;

                          }

                       

                       

                          public BigDecimal getInquiries() {

                              return inquiries;

                          }

                       

                       

                          public void setInquiries(BigDecimal inquiries) {

                              this.inquiries = inquiries;

                          }

                      }

                       

                      and the xhtml page

                       

                      <style>

                                  .scrolls{

                                      width:300px;

                                      height:200px;

                                      overflow:auto;

                                  }

                              </style>   

                              <h:form>

                                  <rich:spacer height="30" />

                                  <rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="400px"

                                      width="700px" id="carList" rows="40" columnClasses="col"

                                      value="#{dataTableScrollerBean.allCars}" var="category" sortMode="single">

                       

                       

                                      <rich:column id="make">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="Make" /></f:facet>

                                          <h:outputText value="#{category.make}" />

                                      </rich:column>

                                      <rich:column id="model">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="Model" /></f:facet>

                                          <h:outputText value="#{category.model}" />

                                      </rich:column>

                                      <rich:column id="price">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="Price" /></f:facet>

                                          <h:outputText value="#{category.price}" />

                                      </rich:column>

                                      <rich:column id="mileage">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="Mileage" /></f:facet>

                                          <h:outputText value="#{category.mileage}" />

                                      </rich:column>

                                      <rich:column width="200px" id="vin">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="VIN" /></f:facet>

                                          <h:outputText value="#{category.vin}" />

                                      </rich:column>

                                      <rich:column id="stock">

                                          <f:facet name="header"><h:outputText styleClass="headerText" value="Stock" /></f:facet>

                                          <h:outputText value="#{category.stock}" />

                                      </rich:column>

                                  </rich:scrollableDataTable>

                                  <rich:spacer height="20px"/>

                                  <a4j:commandButton value="Show Current Selection" reRender="table"

                                      action="#{dataTableScrollerBean.takeSelection}"

                                      oncomplete="javascript:Richfaces.showModalPanel('panel');"/>

                              </h:form>

                       

                       

                      I hope it helps

                      • 8. Re: Problem with rich:scrollableDataTable
                        venuvanama Newbie

                        Hi Jorge,

                         

                        Thank you very much for your response, I will update my richfaces libraries and try. I appreciate your time very much.

                         

                        Venu