1 Reply Latest reply on Apr 30, 2010 6:36 AM by ilya_shaikovsky

    ExtendedDataTable : preserve selection (and some other stuff)

      Hi all,

       

      I've been looking about this on Google since a few days now, and the Scrum iteration ends by friday. So in last resort I come to ask the community to enlightened me.

      Before anything, we're using JSF 1.2 / Richfaces 3.3 / Tomcat 5.5.


      Here is the thing. We have an ExtendedDataTable (it was a simple DataTable since the past 2 weeks but we missed the 'notion of selection').

       

      We want to 'implement' a few things :

      A) Preserve the selected row.
      B) Update the selected row via managed bean (commandLink or commandButton).

       

      A) The EDT (ExtendedDataTable) prints only 6 rows of items, with a DataScroller in header and footer's facets. When we click on a row, the proper action is called in the bean and we can update some TabPane.

       

      However if the user wants to see the next page (click on scroller 'next') and then go back to the previous page, the selection is not preserved (the previously selected row is back to normal style).

       

      How can we preserve/correct it ?

       


      B) Is somehow linked to A) I believe. We want the selected row of the EDT to be updated (in bean and 'visually').
      I tried lot of manipulation with rowKeyVar, which is updated when I click on some external commandButton, but the EDT prints nothing.

       

       

       

      Can you please guide me toward helpful resources ? Concrete sample would be better 'f course, I'll be glad to have a snippet (even if it's very simple).

       

       

      Mugiwara

       

      PS: wtf is the request scope trick ? I can't get how to use and the limitation for 'devlopment' of rowKeyVar property...

       

      Here is the last saving of my current experimentation files:

       

      test.xhtml

       

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:c="http://java.sun.com/jstl/core">
      <a4j:keepAlive beanName="tableBean"/>
      <body>
          <a4j:form>
          <rich:extendedDataTable id="edt"
              rows="6"
              selection="#{tableBean.selection}" value="#{tableBean.data}"
              rowKeyVar="#{tableBean.rowKeyVar}" tableState="#{tableBean.tableState}"
              var="item"
              width="80px" >
              <rich:column colspan="2" width="80px;">
                  <h:outputText value="Nom: #{item}" />
              </rich:column>
         
         
          <f:facet name="footer">
              <rich:datascroller />
          </f:facet>
          </rich:extendedDataTable>
          </a4j:form>
      </body>
      </html>

       

       

      ExtendedDT.java

       

       

      package lu.pragmaconsult.visit.site;

       

      import java.io.Serializable;

       

      import org.richfaces.component.html.HtmlExtendedDataTable;

      import org.springframework.context.annotation.Scope;

      import org.springframework.stereotype.Component;

       

      @Component("tableBean")

      @Scope("request")

      public class ExtendedDT implements Serializable {

       

          private static final long serialVersionUID = -5311408628014648028L;

       

          private HtmlExtendedDataTable table;

       

          private String tableState;

       

          private Object selection;

       

          private String[] data;

       

          private Object rowKeyVar;

       

          public ExtendedDT() {

              this.data = new String[20];

              for (int i = 0; i < 20; i++) {

                  this.data[i] = "Item " + i;

              }

          }

       

          /**

           * @return the tableState

           */

          public final String getTableState() {

              System.out.println("ExtendedDT.getTableState()");

              return this.tableState;

          }

       

          /**

           * @param tableState the tableState to set

           */

          public final void setTableState(String tableState) {

              System.out.println("ExtendedDT.setTableState()");

              System.out.println(tableState + "\n");

              this.tableState = tableState;

          }

       

          /**

           * @return the table

           */

          public final HtmlExtendedDataTable getTable() {

              System.out.println("ExtendedDT.getTable()");

              return this.table;

          }

       

          /**

           * @param table the table to set

           */

          public final void setTable(HtmlExtendedDataTable table) {

              System.out.println("ExtendedDT.setTable()");

              this.table = table;

          }

       

          /**

           * @return the selection

           */

          public final Object getSelection() {

              System.out.println("ExtendedDT.getSelection()");

              return this.selection;

          }

       

          /**

           * @param selection the selection to set

           */

          public final void setSelection(Object selection) {

              System.out.println("ExtendedDT.setSelection()");

              this.selection = selection;

          }

       

          /**

           * @return the data

           */

          public final String[] getData() {

              return this.data;

          }

       

          /**

           * @param data the data to set

           */

          public final void setData(String[] data) {

              this.data = data;

          }

       

          /**

           * @return the rowKeyVar

           */

          public final Object getRowKeyVar() {

              System.out.println("ExtendedDT.getRowKeyVar()");

              return this.rowKeyVar;

          }

       

          /**

           * @param rowKeyVar the rowKeyVar to set

           */

          public final void setRowKeyVar(Object rowKeyVar) {

              System.out.println("ExtendedDT.setRowKeyVar() param: " + rowKeyVar);

              this.rowKeyVar = rowKeyVar;

          }

       

       

       

      }