1 Reply Latest reply on Jul 15, 2008 7:21 AM by ptr83

    srolableDataTable selection not works

    wilfried.deguil

      Hello,

      I use RichFaces 3.2.1_GA and i have a problem with the rich:scrollableDataTable, and the selection of row.

      When I start my applicaction, the scrollableDataTable is displayed correctly.
      When I select a row into scrollableDataTable an display this selection in the dataTable to a modalPanel, the dataTable is empty.

      I'm start since the demo http://livedemo.exadel.com/richfaces-demo/richfaces/scrollableDataTable.jsf?c=scrollableDataTable

      My xHtml code :

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:s="http://jboss.com/products/seam/taglib"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:rich="http://richfaces.org/rich"
      template="layout/templateWD.xhtml"
      xmlns:a4j="http://richfaces.org/a4j">

      <ui:define name="body">
      <h:form>
      <rich:spacer height="30"/>
      <rich:scrollableDataTable rowKeyVar="rkv" frozenColCount="1" height="400px"
      width="300px" id="allPerson" rows="30" columnClasses="col"
      value="#{personsList}" var="item" sortMode="single"
      binding="#{table}" selection="#{selection}" hideWhenScrolling="true">
      <rich:column id="name">
      <f:facet name="header"><h:outputText styleClass="headerText" value="Name" /></f:facet>
      <h:outputText value="#{item.name}"/>
      </rich:column>
      <rich:column id="firstanme">
      <f:facet name="header"><h:outputText styleClass="headerText" value="Firstname" /></f:facet>
      <h:outputText value="#{item.firstname}"/>
      </rich:column>
      <rich:column id="adressStreet">
      <f:facet name="header"><h:outputText styleClass="headerText" value="Address" /></f:facet>
      <h:outputText value="#{item.adressStreet}"/>
      </rich:column>
      </rich:scrollableDataTable>
      <rich:spacer height="20px"/>
      <a4j:commandButton value="Show Current Selection" reRender="table"
      oncomplete="javascript:Richfaces.showModalPanel('panel');"
      action="#{personBean.takeSelection}"/>
      </h:form>
      <rich:modalPanel id="panel" autosized="true">
      <f:facet name="header">
      <h:outputText value="Selected Rows"/>
      </f:facet>
      <f:facet name="controls">
      <span style="cursor:pointer" onclick="javascript:Richfaces.hideModalPanel('panel')">X
      </f:facet>
      <rich:dataTable value="#{selectedPersons}" var="sel" id="table">
      <rich:column>
      <f:facet name="header"><h:outputText value="Name" /></f:facet>
      <h:outputText value="#{sel.name}" />
      </rich:column>
      <rich:column id="Firstname">
      <f:facet name="header"><h:outputText value="Firstname" /></f:facet>
      <h:outputText value="#{sel.firstname}" />
      </rich:column>
      <rich:column id="Address">
      <f:facet name="header"><h:outputText value="Address" /></f:facet>
      <h:outputText value="#{sel.adressStreet}" />
      </rich:column>
      </rich:dataTable>
      </rich:modalPanel>
      </ui:define>
      </ui:composition>

      and my java code :


      package fr.horoquartz.geveseam.bean;

      @Stateful
      @Name("personBean")
      @JndiName("Geve/PersonBean/remote")
      @Scope(ScopeType.CONVERSATION)
      public class PersonBean implements Serializable, PersonRemote {
      private static final long serialVersionUID = 1L;


      @DataModel
      private List personsList = null;
      private SimpleSelection selection = new SimpleSelection();
      private UIScrollableDataTable table = null;
      private ArrayList selectedPersons = new ArrayList();

      @DataModelSelection("personsList")
      @Out(required=false)
      private Person person;

      public List getPersonsList() {
      return personsList;
      }

      public void setPersonsList(List personsList) {
      this.personsList = personsList;
      }

      public Person getPerson() {
      return person;
      }

      public void setPerson(Person person) {
      this.person = person;
      }

      public SimpleSelection getSelection() {
      return selection;
      }

      public void setSelection(SimpleSelection selection) {
      this.selection = selection;
      }

      public UIScrollableDataTable getTable() {
      return table;
      }

      public void setTable(UIScrollableDataTable table) {
      this.table = table;
      }

      public ArrayList getSelectedPersons() {
      return selectedPersons;
      }

      public void setSelectedPersons(ArrayList selectedPersons) {
      this.selectedPersons = selectedPersons;
      }

      @SuppressWarnings("unchecked")
      @Factory("personsList")
      public void findPersons()
      {
      // logger.info("findPersons");
      // TODO : getAllPerson();
      // personsList = getAllResidants();
      personsList = em.createQuery("select person from Person person order by person.id desc").getResultList();
      // messageList = em.createQuery("select msg from Message msg order by msg.datetimeMess desc").getResultList();
      }

      public String takeSelection() {
      getSelectedPersons().clear();
      System.out.println(getSelection().size());
      if (getSelection().isSelectAll()) {
      getSelectedPersons().addAll(personsList);
      }
      else {
      Iterator iterator = getSelection().getKeys();
      while (iterator.hasNext()) {
      SimpleRowKey key = (SimpleRowKey) iterator.next();
      table.setRowKey(key);
      if (table.isRowAvailable()) {
      getSelectedPersons().add((Person)table.getRowData());
      }

      }
      }
      return null;
      }

      @Remove @Destroy
      public void destroy() {
      System.out.println("personBean : destroy");
      }
      }


      In the function takeSelection the getSelection().size() is always equal to 0.

      Does anyone knows a solution on this?

      thanks