2 Replies Latest reply on May 28, 2009 2:07 PM by Thomas W

    Capturing scrollableDataTable selection w/o full table decod

    Thomas W Newbie

      I have a scrollableDataTable for which I want to record the selection in a bean. The table should not re-render as part of selection change.

      <rich:scrollableDataTable id="someTable"
      selectionMode="multi"
      selection="#{someAction.selection}"
      ....
      <a:support event="onselectionchange"
      reRender="region1, region2"
      limitToList="true"
      ajaxSingle="true"
      status="globalStatus"/>

      The problem with this setup: Whenever selection changes, the entire table is processed on the server side. What I need is the ability to just capture the selection and reRender other sections of the screen outside of the table region/form. No processing of the table component.

      Would it be possible (using the RF infrastructure) to define a separate form for the selection only and trigger its submit from the onselectionchange handler?

        • 1. Re: Capturing scrollableDataTable selection w/o full table d
          Konstantin Mishin Novice

          It isn't possible to define a separate form for the selection now.

          • 2. Re: Capturing scrollableDataTable selection w/o full table d
            Thomas W Newbie

            This is really something that should be addressed. Selection on the table typically does not change what is shown in the table and therefore any full processing of the table on the server is unwanted overhead. This is also not too difficult to accomplish. I will post my solution below in case someone else needs it and log a JIRA enhancement request.


            Define separate form for selection:

             <h:form>
             <a:jsFunction name="setScrollableDataTableSelection"
             reRender="selectionDetailArea"
             limitToList="true"
             ajaxSingle="false"
             <a:actionparam name="param1" assignTo="#{myAction.scrollableDataTableSelection}" />
             </a:jsFunction>
             </h:form>
            

            Link it from the table:
            onselectionchange="javascript:setScrollableDataTableSelection($('#{rich:clientId('myTable')}:s').value);"
            

            (to replace existing onselectionchange a:support tag.)

            Finally, the Java code needs to parse the selection string and in this case converts it into SimpleSelection:

             public void setScrollableDataTableSelection(String selection) {
             log.info("scrollableDataTableSelection {0}", selection);
             if (selection == null) {
             return;
             }
             String[] tokens = selection.split(";");
             SimpleSelection newSelection = new SimpleSelection();
             for (String token : tokens) {
             Matcher m = Pattern.compile("(\\d+),(\\d+)").matcher(token);
             if (m.find()) {
             int startIndex = Integer.parseInt(m.group(1));
             int endIndex = Integer.parseInt(m.group(2));
             for (int i=startIndex; i<=endIndex; i++) {
             if (i <= this.rowIds.size()) {
             newSelection.addKey(this.rowIds.get(i).intValue());
             }
             }
             }
             }
             this.selection = newSelection;
             }