8 Replies Latest reply on May 20, 2010 6:40 AM by Jozsef Szalai

    DataScroller and selectable rows

    B Tomic Newbie

      Is it possible to select multiple rows found on different pages using DataScroller and whatever datatable-type component?
      For example, I want to select one row on a first page and two more on the second page.

      I'm not able to test this out at the moment, so I'm posting here...

      Thanks for the patience.

        • 1. Re: DataScroller and selectable rows
          Ilya Shaikovsky Master

          It's possible and the implementation depends on concrete case.. you want to use checkboxes, or just row highlight and so on? And b.t.w. do not try with scrollable table because it has it's own scroll so it's not designed to be used with datascroller.

          • 2. Re: DataScroller and selectable rows
            B Tomic Newbie

            Thank you for the reply.

            you want to use checkboxes, or just row highlight and so on?

            Well, checkboxes would be nice, but honestly, I'll go for the easiest solution here.
            do not try with scrollable table

            I'm aware about the scrollable table's differences, and I was attempting to use extended datatable as it seems to support both the scroller and multiple row selection.

            Would you, please, give me some guidance or a pointer to some reading material on implementing this? I'm quite new to RichFaces, so I could really use a hand.

            Thanks a bunch!

            • 3. Re: DataScroller and selectable rows
              Ilya Shaikovsky Master

              Simple sample that I already commited to richfaces-demo but it will be alive after 3.3.2 GA:

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml"
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:a4j="http://richfaces.org/a4j"
               xmlns:rich="http://richfaces.org/rich">
              
              <ui:composition>
               <h:form>
               <h:panelGrid columns="2" columnClasses="top , top">
               <rich:extendedDataTable
               value="#{extendedTableBean.capitalsDataModel}" var="cap" id="table"
               width="580px" height="400px"
               sortMode="#{extendedTableBean.sortMode}"
               selectionMode="#{extendedTableBean.selectionMode}"
               tableState="#{extendedTableBean.tableState}"
               selection="#{extendedTableBean.selection}">
               <rich:column sortable="false" label="Flag">
               <f:facet name="header">
               <h:outputText value="Flag" />
               </f:facet>
               <h:graphicImage value="#{cap.stateFlag}" />
               </rich:column>
               <rich:column sortable="true" sortBy="#{cap.state}"
               filterBy="#{cap.state}" filterEvent="onkeyup" width="170px"
               label="State Name">
               <f:facet name="header">
               <h:outputText value="State Name" />
               </f:facet>
               <h:outputText value="#{cap.state}" />
               </rich:column>
               <rich:column sortable="true" sortBy="#{cap.name}"
               filterBy="#{cap.name}" filterEvent="onkeyup" width="170px"
               label="State Capital">
               <f:facet name="header">
               <h:outputText value="State Capital" />
               </f:facet>
               <h:outputText value="#{cap.name}" />
               </rich:column>
               <rich:column sortable="false" label="Time Zone">
               <f:facet name="header">
               <h:outputText value="Time Zone" />
               </f:facet>
               <h:outputText value="#{cap.timeZone}" />
               </rich:column>
               <a4j:support reRender="selectiontable"
               action="#{extendedTableBean.takeSelection}"
               event="onselectionchange" />
               </rich:extendedDataTable>
               <h:panelGroup layout="block" style="width:250px">
               <rich:panel>
               <f:facet name="header">
               <h:outputText value="Sort/Selection modes changing" />
               </f:facet>
               <h:panelGrid columns="2">
               <h:outputText value="Sort Mode:" />
               <h:selectOneMenu value="#{extendedTableBean.sortMode}">
               <f:selectItem itemLabel="Single" itemValue="single" />
               <f:selectItem itemLabel="Multi" itemValue="multi" />
               <a4j:support event="onchange" ajaxSingle="true" reRender="table" />
               </h:selectOneMenu>
               <h:outputText value="Selection Mode:" />
               <h:selectOneMenu value="#{extendedTableBean.selectionMode}">
               <a4j:support ajaxSingle="true" event="onchange" reRender="table" />
               <f:selectItem itemLabel="Single" itemValue="single" />
               <f:selectItem itemLabel="Multi" itemValue="multi" />
               <f:selectItem itemLabel="None" itemValue="none" />
               </h:selectOneMenu>
               </h:panelGrid>
               </rich:panel>
               <rich:panel>
               <f:facet name="header">
               <h:outputText value="Currently selected rows:" />
               </f:facet>
               <rich:dataTable value="#{extendedTableBean.selectedCapitals}"
               var="sel" id="selectiontable">
               <rich:column>
               <h:graphicImage value="#{sel.stateFlag}" />
               </rich:column>
               <rich:column>
               <h:outputText value="#{sel.state}" />
               </rich:column>
               <rich:column>
               <h:outputText value="#{sel.name}" />
               </rich:column>
               <rich:column>
               <h:outputText value="#{sel.timeZone}" />
               </rich:column>
               </rich:dataTable>
               </rich:panel>
               </h:panelGroup>
               </h:panelGrid>
               </h:form>
              </ui:composition>
              
              </html>
              

              /**
               *
               */
              package org.richfaces.demo.extendedDataTable;
              
              import java.util.ArrayList;
              import java.util.Iterator;
              import java.util.List;
              
              import org.richfaces.demo.capitals.Capital;
              import org.richfaces.demo.datafilterslider.DemoInventoryItem;
              import org.richfaces.model.DataProvider;
              import org.richfaces.model.ExtendedTableDataModel;
              import org.richfaces.model.selection.Selection;
              import org.richfaces.model.selection.SimpleSelection;
              
              /**
               * @author Ilya Shaikovsky
               *
               */
              public class ExtendedTableBean {
               private String sortMode="single";
               private String selectionMode="multi";
               private Object tableState;
               private Selection selection = new SimpleSelection();
               private List<Capital> capitals = new ArrayList<Capital>();
               private ExtendedTableDataModel<Capital> dataModel;
               private List<Capital> selectedCapitals = new ArrayList<Capital>();
              
               public String getSortMode() {
               return sortMode;
               }
              
               public void setSortMode(String sortMode) {
               this.sortMode = sortMode;
               }
              
               public String getSelectionMode() {
               return selectionMode;
               }
              
               public void setSelectionMode(String selectionMode) {
               this.selectionMode = selectionMode;
               }
              
               public ExtendedTableBean() {
               }
              
               public void takeSelection(){
               selectedCapitals.clear();
               Iterator<Object> iterator = getSelection().getKeys();
               while (iterator.hasNext()) {
               Object key = iterator.next();
               selectedCapitals.add(getCapitalsDataModel().getObjectByKey(key));
               }
               }
              
               public ExtendedTableDataModel<Capital> getCapitalsDataModel() {
               if (dataModel == null) {
               dataModel = new ExtendedTableDataModel<Capital>(new DataProvider<Capital>(){
              
               private static final long serialVersionUID = 5054087821033164847L;
              
               public Capital getItemByKey(Object key) {
               for(Capital c : capitals){
               if (key.equals(getKey(c))){
               return c;
               }
               }
               return null;
               }
              
               public List<Capital> getItemsByRange(int firstRow, int endRow) {
               return capitals.subList(firstRow, endRow);
               }
              
               public Object getKey(Capital item) {
               return item.getName();
               }
              
               public int getRowCount() {
               return capitals.size();
               }
              
               });
               }
               return dataModel;
               }
              
               public void setCapitals(List<Capital> capitals) {
               this.capitals = capitals;
               }
              
               public Object getTableState() {
               return tableState;
               }
              
               public void setTableState(Object tableState) {
               this.tableState = tableState;
               }
              
               public Selection getSelection() {
               return selection;
               }
              
               public void setSelection(Selection selection) {
               this.selection = selection;
               }
              
               public List<Capital> getSelectedCapitals() {
               return selectedCapitals;
               }
              
               public void setSelectedCapitals(List<Capital> selectedCapitals) {
               this.selectedCapitals = selectedCapitals;
               }
              
              }
              
              


              Not the concrete solution for your case but you should check to get selection management idea so you will be able to implement your case with analogous code.

              • 4. Re: DataScroller and selectable rows
                B Tomic Newbie

                Ok, I'll study your code and I'll try implementing the solution.
                Thanks a lot for this!

                • 5. Re: DataScroller and selectable rows
                  Jozsef Szalai Newbie

                  Hi  Ilya,

                  I am new in richfaces. Tried to implement your example about extendedDataTable  in NetBeans 6.8. inside the portlet running on JBoss Portal 2.7.2-ga (OS: Windows XP Professional version-2002 with service pack 3)  and got the following error:

                   

                  11:07:39,786 INFO  [STDOUT] -------------countryChanged: 2
                  11:07:39,786 INFO  [STDOUT] ......dataModel = null........currencies.size(): 1
                  11:07:39,786 INFO  [STDOUT] ......getRowCount 1..........
                  11:07:39,786 INFO  [STDOUT] ......dataModel: 1..........

                  11:07:39,786 INFO  [STDOUT] ......dataModel: 1..........
                  11:07:39,786 INFO  [STDOUT] ......dataModel: 1..........
                  11:07:39,786 INFO  [STDOUT] ......dataModel: 1..........
                  11:07:39,786 INFO  [STDOUT] ......dataModel: 1..........
                  11:07:39,817 INFO  [STDOUT] ......dataModel: 1..........
                  11:07:39,864 INFO  [STDOUT] ......getItemsByRange 0 - 1
                  11:07:39,864 INFO  [STDOUT] ......sublist= 1
                  11:07:39,864 ERROR [STDERR] 2010.05.19. 11:07:39 com.sun.facelets.FaceletViewHandler handleRenderException
                  SEVERE: Error Rendering View[/country.xhtml]

                  java.lang.NullPointerException
                          at org.richfaces.renderkit.html.TableSelectionRendererContributor$2.process(TableSelectionRendererContributor.java:278)
                          at org.richfaces.model.ExtendedTableDataModel.walk(ExtendedTableDataModel.java:110)
                          at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:1133)
                          at org.richfaces.renderkit.html.TableSelectionRendererContributor.encodeSelection(TableSelectionRendererContributor.java:265)
                          at org.richfaces.renderkit.html.TableSelectionRendererContributor.encode(TableSelectionRendererContributor.java:228)
                          at org.richfaces.renderkit.AbstractExtendedTableRenderer.contributorsEncodeHere(AbstractExtendedTableRenderer.java:1821)
                          at org.richfaces.renderkit.html.ExtendedDataTableRenderer.doEncodeEnd(ExtendedDataTableRenderer.java:354)
                          at org.richfaces.renderkit.html.ExtendedDataTableRenderer.doEncodeEnd(ExtendedDataTableRenderer.java:387)
                          at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
                          at org.richfaces.renderkit.AbstractExtendedTableRenderer.encodeEnd(AbstractExtendedTableRenderer.java:1371)
                          at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
                          at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:242)
                          at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:178)
                          at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:126)
                          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
                          at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
                          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                          at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
                          at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
                          at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:301)
                          at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:296)
                          at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
                          at org.richfaces.renderkit.html.SimpleTogglePanelRenderer.encodeChildren(SimpleTogglePanelRenderer.java:188)
                          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                          at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
                          at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
                          at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
                          at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
                          at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
                          at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:680)
                          at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:551)
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
                          at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                          at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
                          at org.jboss.portletbridge.application.PortletViewHandler.renderView(PortletViewHandler.java:231)
                          at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                          at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
                          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                          at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                          at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                          at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                          at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                          at java.lang.Thread.run(Thread.java:619)
                  11:07:40,364 INFO  [STDOUT] ......dataModel: 1..........

                   

                   

                  I have attached my example: country.xhtml , CountryAdminManagedBean.java, my web-project's web-inf and a doc containing libraries from project property. Have to mention that I am using the RichFaces 3.3.3 Final version. (but started with version 3.3.3 CR1.

                   

                  Colud you look at it and give me an advice where the problem is?

                   

                  Thank you in advance,

                  Jozsef

                  • 6. Re: DataScroller and selectable rows
                    Ilya Shaikovsky Master

                    does the same work in non-portan environment?

                    • 7. Re: DataScroller and selectable rows
                      Jozsef Szalai Newbie

                      Thank you for your reply. The problem  exists also in a non-portal environment.

                      • 8. Re: DataScroller and selectable rows
                        Jozsef Szalai Newbie

                        Hi Ilya,

                         

                        Could you also provide us the whole example (we mean not only the XHTML, but also the backing bean) of Edit Data Table with modal panel.

                        Maybe it is a simple question where to find them but unfortunetly we do not know  it.

                         

                        We are waiting for you reply. It is a quite important question to us.

                         

                        Thank you,

                        Jozsef Szalai