8 Replies Latest reply on Jul 30, 2010 3:12 AM by tzelve

    Sorting with scrollableDataTable

    Antonio Broughton Newbie

      Hi, I am new to using Seam, and I am trying to get sorting working with a richfaces scrollableDataTable.

      I currently have it displaying, however, when I click on the column headers, it exceptions saying that the selection property does not exist.

      This is correct, as I have not implemented the selection.

      My main question is, how do I go about implementing this?

      I currently have:

        <rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="400px" width="700px"
      id="currentSheetListView" rows="40" columnClasses="col"
      value="#{inputListAction.resultList}" var="inputList" sortMode="single" selection="#{inputListScroller.selection}">

      But I am not sure what to put into inputListScroller bean... ie: I cannot find any examples of how this is used...

      I guess my main question is, where can I find an example on howto implement the selection code for a scrollableDataTable.

      I am also wanting to sort the data directly from the database I am getting the data from... is this possible?


      Antonio Broughton

        • 1. Re: Sorting with scrollableDataTable
          Ariel T Newbie

          Here you have a working example, but sorting doesn't work.
          After you sort a column, you won't get the corresponding object from the list. If you know how to solve this, please let me know.


                          rendered="#{not empty paisesList.resultList}"
                          <rich:column id="idpais" sortable="#{paisesList.sortable}" sortBy="#{paises.idpais}">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="ID" /></f:facet>
                                  <h:outputText value="#{paises.idpais}" />
                          <rich:column id="descripcion" sortable="true" sortBy="">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="Descripcion" /></f:facet>
                                  <h:outputText value="#{paises.descripcion}" />
                          <rich:column id="isoNumber" sortable="#{paisesList.sortable}" sortBy="#{paises.isoNumber}">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="ISO #" /></f:facet>
                                  <h:outputText value="#{paises.isoNumber}" />
                          <rich:column id="iso2Chars" sortable="#{paisesList.sortable}" sortBy="#{paises.iso2Chars}">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="ISO 2" /></f:facet>
                                  <h:outputText value="#{paises.iso2Chars}" />
                          <rich:column id="iso3Chars" sortable="#{paisesList.sortable}" sortBy="#{paises.iso3Chars}">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="ISO 3" /></f:facet>
                                  <h:outputText value="#{paises.iso3Chars}" />
                          <rich:column id="caracteristica" sortable="#{paisesList.sortable}" sortBy="#{paises.caracteristica}">
                                      <f:facet name="header"><h:outputText styleClass="headerText" value="Caracteristica" /></f:facet>
                                  <h:outputText value="#{paises.caracteristica}" />
                      <a4j:commandButton value="Show Current Selection"  
                          action="#{paisesList.takeSelection}" />


          public class PaisesList extends EntityQuery<Paises> {
               private static final long serialVersionUID = 1230800736229942471L;
               private static final String[] RESTRICTIONS = {
                         "lower(paises.descripcion) like concat(lower(#{paisesList.paises.descripcion}),'%')",
                         "lower(paises.caracteristica) like concat(lower(#{paisesList.paises.caracteristica}),'%')", };
               private static final boolean SORTABLE = false;
               private Paises paises = new Paises();
               private SimpleSelection selection = new SimpleSelection();
               public SimpleSelection getSelection() {
                    return selection;
               public void setSelection(SimpleSelection selection) {
                    this.selection = selection;
               private List<Paises> selectedPaises = new ArrayList<Paises>();
               public List<Paises> getSelectedPaises() {
                    return selectedPaises;
               public void setSelectedPaises(List<Paises> selectedPaises) {
                    this.selectedPaises = selectedPaises;
               public String takeSelection() {
                    Iterator<SimpleRowKey> iterator = getSelection().getKeys();
                    while (iterator.hasNext())
                         SimpleRowKey key = iterator.next();
                         System.out.println("key: " + key.intValue());
                    System.out.println("Mostrando paises seleccionados:");
                    for (Paises p : getSelectedPaises()) {
                    System.out.println("Fin Mostrando paises seleccionados");
                    return null;
               public String getEjbql() {
                    return "select paises from Paises paises";
               public Integer getMaxResults() {
                    return 50;
               public Paises getPaises() {
                    return paises;
               public List<String> getRestrictions() {
                    return Arrays.asList(RESTRICTIONS);
               public boolean isSortable() {
                    return SORTABLE;

          • 2. Re: Sorting with scrollableDataTable
            Ariel T Newbie

            Sorry I expressed myself wrong.
            Sorting WORKS but, Selection AFTER Sorting does not work.

            Seems like the solution is this (see code below) but I can't make the binding to UIScrollableDataTable work.

                   public String takeSelection() {
                            Iterator<Object> iterator = getSelection().getKeys();
                            while (iterator.hasNext()){
                                    Object key = iterator.next();
                                    if (table.isRowAvailable()) {
                                            getSelectedPaises().add((Paises) table.getRowData());
                            System.out.println("Mostrando paises seleccionados:");
                            for (Paises p : getSelectedPaises()) {
                            System.out.println("Fin Mostrando paises seleccionados");
                            return null;

            • 3. Re: Sorting with scrollableDataTable
              nathan dennis Expert

              did you ever get that binding to work? im having the same trouble.

              • 4. Re: Sorting with scrollableDataTable
                Thai Dang Vu Apprentice

                Did the SimpleSelection work for you? It doesn't for me. If it works for you, could you please send me an example? My email address is dxxvi at dangvufirm dot com.

                Thank you.

                • 5. Re: Sorting with scrollableDataTable
                  Thai Dang Vu Apprentice

                  Did you ever get that SimpleSelection work? I don't. If it works for you, could you please send me an example? My email address is dxxvi at dangvufirm dot com.

                  Thank you.

                  • 6. Re: Sorting with scrollableDataTable
                    Nagendra krishnawat Newbie

                    Did selection worked you you guys, it never worked for me, beside it gives a javascript err on load. I am using seam 3.3.1 which is almost latest version.

                    • 7. Re: Sorting with scrollableDataTable
                      Nagendra krishnawat Newbie

                      Can anyone give me a working code of this.

                      • 8. Re: Sorting with scrollableDataTable
                        tzelve Newbie

                        I found a way to have correct selections and sorting with scrollableDataTable. The value property point to a property of extended type org.richfaces.model.ScrollableTableDataModel. In your class (witch extends org.richfaces.model.ScrollableTableDataModel) you must implement both getId and reverse getObjectById with a id for line (in my project i use the index position in the original List). After this the selection returns to you the correct list of selected id and sorting working correct.