javajsfrichfacesrichdatatable

Extended Data Table and DataScroller


<rich:extendedDataTable sortMode="single" width="700px" value="#{gpsReport.reportSummary}"
                                                enableContextMenu="true" var="gps"
                                                selectionMode="single"
                                                rowClasses="tableRow1, tableRow2"
                                                id="tbl_gps" height="301px" rows="#{gpsReport.rowCount}" rowKeyVar="row">

                            <rich:column label="User" style="text-align: center" width="100px" >

                                <f:facet name="header">
                                    <h:outputText value="User" />
                                </f:facet>
                                <h:outputText value="#{gps.currentUser}" />

                            </rich:column>

                            <rich:column label="Time Stamp" style="text-align: center" width="140px" >

                                <f:facet name="header">
                                    <h:outputText value="Time Stamp" />
                                </f:facet>
                                <h:outputText value="#{gps.modifiedDate}" />

                            </rich:column>

                            <rich:column label="Latitude" style="text-align: center" width="110px" >

                                <f:facet name="header">
                                    <h:outputText value="Latitude" />
                                </f:facet>
                                <h:outputText value="#{gps.latitude}" />

                            </rich:column>

                            <rich:column label="Longitude" style="text-align: center" width="110px" >

                                <f:facet name="header">
                                    <h:outputText value="Longitude" />
                                </f:facet>
                                <h:outputText value="#{gps.longitude}" />

                            </rich:column>

                            <rich:column label="Location" style="text-align: center" width="240px" >

                                <f:facet name="header">
                                    <h:outputText value="Location" />
                                </f:facet>
                                <h:outputText value="#{gps.location}" />

                            </rich:column>

                        </rich:extendedDataTable>

                        <rich:datascroller align="center" for="tbl_gps"  />

Why does this code doesn't work? Am I missing something? This is the very same implementation I've used on the other page, it works actually. But no luck this time.


Solution

  • The problem is that the list contents is refilled every time the managed bean is created. Since the managed bean has a request scope, it will be created on every action (this includes ajax actions). Please refer to How to choose the right bean scope? and the link provided there where it explains the scopes for managed beans and provides good examples for their usage.

    Since you're using JSF 1.2, you can't use the view scope. Instead, to solve this problem you have two ways:

    1. Change the scope of your managed bean to session scope. It will solve your problem but the managed bean will live until the user session expires, not a really good solution.

    2. Maintain your managed bean in request scope and use the power of RichFaces 3.3 and @KeepAlive annotation. This annotation will make your request managed to live while the user is still in the same view (pretty similar to view scope). Its usage is pretty simple:

      @KeepAlive
      public class GpsReport {
          //managed bean definition...
      }