1 Reply Latest reply on May 30, 2011 10:41 AM by khowe

    RF4: rich:dataGrid - Changing Page?

    khowe

      I'm using rich:dataGrid to display > 1000 of contacts.

      I attempting to build a list of letters (each an a4j:commandLink) where you click on a letter and it it takes you to the page in the table at the first instance of a Contact with that letter.

       

      So, I thought I had it working by binding the datagrid to my bean and accessing the grid's footer and calling setPage (See function ContactMgr::changepage() below), but it only appears to be working randomly?  I do know my bean functions are being called with the expected data; however, I'm guessing I'm probably not calling the RichFaces function correctly (newbie-ism).

       

      Here's the snippets of what I'm attempting...  If it isn't enough of the code, I'll be happy to post more...

      Note: I've simplified to only have the commandLink for the letter "A". 

       

      I'd appreciate any help!  Kind regards,

      Katie

       

      directory.xhtml-----------------------------------------------

         <rich:panel>

         <h:form>

              <a4j:commandLink id="letter_a" ajaxSingle="true" render="table_contacts" action="#{contactMgr.changepage}" >

                    <f:setPropertyActionListener value="1" target="#{contactMgr.contactPage}" />

                    <h:outputText value="A"/>

               </a4j:commandLink>

          </h:form>

         </rich:panel>

          </rich:panel>

         <rich:panel>

          <h:form>

           <rich:dataGrid value="#{contactMgr.contacts}" var="contact" binding="#{contactMgr.datagrid}"

            ajaxKeys="#{contactMgr.rowsToUpdate}" columns="#{contactMgr.gridColumns}" elements="#{contactMgr.gridElementPerPage}"

            width="600px" border="0" id="table_contacts"

            >

       

      ContactMgr.java-------------------------------------------

      private ArrayList<Contact> contactList = new ArrayList<Contact>();

      private int gridColumns = 3;

      private int gridElementPerPage = 9;

      private int contactPage = 0;

      private UIDataGrid datagrid;

       

      public void changepage() {

             LogWriter.INFO("Changepage: " + this.contactPage);

             Map<String, UIComponent> mFacets = datagrid.getFacets();

             UIDataScroller footer = (UIDataScroller) mFacets.get("footer");

             if (footer != null) {

                   footer.setPage(this.contactPage);

             }

      }

       

      public UIDataGrid getDatagrid() {
        return this.datagrid;
      }

      public void setDatagrid(UIDataGrid grid) {
        this.datagrid = grid;
      }

      public int getContactPage() {
        return this.contactPage;
      }

      public void setContactPage(int contactpage) {
        this.contactPage = contactpage;
        //LogWriter.INFO("set contact page: " + this.contactPage);
      }

        • 1. Re: RF4: rich:dataGrid - Changing Page?
          khowe

          What a difference a few days off makes...

          OK I figured out I was definitely trying the really overly difficult way by binding the datagrid and attempting to access its internal datascroller.  Instead, I've now added my own datascroller to the page and am calling the switchToPage javascript on it... 

          Here's the code snippets for anyone who stumbles in after me...

          I'm not putting in the code for contactMgr & supporting classes, but if your curious, the alphaNumList is just an Array list of a simple class that just has a 2 class members:

              name - which has the Alphabet character

              page - first page with a contact with this letter

           

          directory.xhtml-----------------------------------------------

             <rich:panel>
             <center>
             <h:form>
                   <a4j:repeat value="#{contactMgr.alphaNumList}" var="alphas" id="repeat">
                         <a4j:commandLink ajaxSingle="true"
                                render="table_contacts,contact_table_scroller"
                                oncomplete="#{rich:component('contact_table_scroller')}.switchToPage(#{alphas.page})">
                                    <h:outputText value="#{alphas.name}      " styleClass="sf-alphanum"/>
                          </a4j:commandLink>
                   </a4j:repeat>
              </h:form>
              </center>
             </rich:panel>
             <rich:panel>
              <h:form>
                <center>

                    <rich:dataScroller for="table_contacts" maxPages="10" id="contact_table_scroller" /></center>
                    <rich:dataGrid value="#{contactMgr.contacts}" var="contact"
                          ajaxKeys="#{contactMgr.rowsToUpdate}" columns="#{contactMgr.gridColumns}" elements="#{contactMgr.gridElementPerPage}"
                          width="600px" border="0" id="table_contacts" >