1 Reply Latest reply on Jul 31, 2011 7:49 PM by Andrew Dambrosio

    Datatable not updating when clicking on commandlink

    Andrew Dambrosio Newbie

      I have a datatable with a column that contains an up arrow and another column that has a down arrow. These allow you to move the row up and down. However, when I click on them, the moveUp method in the bean is triggered and the order is updated, but I don't see this in my browser. When I trigger it again, I can tell (with printlns) that the order is reset to what was originally retrieved from the database.

      Below is an extract of my JSP and bean. Please help

       

      <h:panelGrid id="pgPage" columns="1" width="100%">

           <rich:dataTable binding="#{MyBean.staffTable}" value="#{MyBean.staffList}" var="staff"

                                                          rowClasses="row1, row2" id="staffTable" rows="20"

                                                          columnClasses="50,100,100,100"

                                                          onRowMouseOver="this.style.backgroundColor='#B5F3FB'"

                                                          onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"

                                                          style="width:770px;align:center;">

                                                          <f:facet name="header">

                                                              <rich:columnGroup>

                                                                  <rich:column width="27%">

                                                                      <h:outputText value="Name" />

                                                                  </rich:column>

                                                    <rich:column width="10">

                                                                      <h:outputText value="Up" />

                                                                  </rich:column>


                                                        </f:facet>

                                                            

                                                        <rich:column>

                                                              <h:outputText value="#{staff.staffname}" />

                                                          </rich:column>

                                                   <rich:column>

                                                           

                                                             <a4j:commandLink reRender="pgPage" actionListener="#{MyBean.moveUp}">

                                                                  <h:graphicImage url="/images/move_up.png" style="border:0;width:15px;height:15px;"/>

                                                              </a4j:commandLink>

       

                                              </rich:column>

                                    </rich:dataTable>


       

      </h:panelGrid>

       

       

       

      public class MyBean extends AbstractPageBean {

           private org.richfaces.component.html.HtmlDataTable staffTable = new org.richfaces.component.html.HtmlDataTable();

          public org.richfaces.component.html.HtmlDataTable getStaffTable() {

              return staffTable;

          }

          public void setStaffTable(org.richfaces.component.html.HtmlDataTable hot) {

              this.staffTable = hot;

          }

       

       

          

           public void moveUp(ActionEvent e) throws Exception {

              try {

                  int selectedIndex = staffTable.getRowIndex();

                  WWWWebsiteStaff selectedStaff = (WWWWebsiteStaff) staffTable.getRowData();

                  if (selectedIndex == 0) {

                      //do nothing

                  } else {

                      staffList.remove(selectedIndex);

                      staffList.add(selectedIndex - 1, selectedStaff);

                  }

              } catch (Exception ex) {

                  ex.printStackTrace();

              }

              staffList = getStaffList();

          }

      }