2 Replies Latest reply on Nov 3, 2011 2:12 PM by aaroniw

    extendedDataTableModel update

    hypnosat7

      Hello,

       

        I'm facing some problems when trying to update an ExtendedTableDataModel. In fact I'm trying to refresh a list of flights after adding a new one.

      When I save the new flight, it is added in the database but the extendedDataTable is not refreshed.

       

       

      So the code in my jsp for refreshing an extendedDataTable is:

                   <a4j:commandButton action="#{flightsController.save}" value="Save"
                          reRender="formTableFlight">
                      </a4j:commandButton>
      
      

       

      And the 'save' method in my controller :

       

      public String save() {
              for (Company c : companies) {
                  if(companyName.equals(c.getName()))
                          company = c;
              }
              flight.setCompany(company);
              flightsService.add(flight);
              flights.add(flight);
              form.setRendered(false);
              addCommand.setRendered(true);
              return null;
          }

       

      The extendedDataTable is declared as follows :

       

      <h:form binding="#{flightsController.formTableFlight}"
                      id="formTableFlight">
      
                      <rich:extendedDataTable
                          value="#{flightsController.extendedTableDataModel}" var="flight"
                          selection="#{flightsController.selectionFlight}" id="tableFlight"
                          sortMode="single" selectionMode="single" width="500px"
                          height="200px">
      
                          <f:facet name="header">
                              <h:outputText value="Flight" />
                          </f:facet>
      
                          <rich:column sortable="false" label="Code" id="col_code">
                              <f:facet name="header">
                                  <h:outputText value="Code" id="code" />
                              </f:facet>
                              <h:outputText value="#{flight.id}" id="flight_id" />
                          </rich:column>
      
                          <rich:column sortable="true" label="Departure" id="col_departure">
                              <f:facet name="header">
                                  <h:outputText value="Departure" id="departure" />
                              </f:facet>
                              <h:outputText value="#{flight.departure}" />
                          </rich:column>
      
                          <rich:column sortable="true" label="Departure" id="col_destination">
                              <f:facet name="header">
                                  <h:outputText value="Destination" id="destination" />
                              </f:facet>
                              <h:outputText value="#{flight.destination}" />
                          </rich:column>
      
                          <rich:column sortable="false" label="actions" id="col_actions">
                              <f:facet name="header">
                                  <h:outputText value="Actions" id="actions" />
                              </f:facet>
                              <h:panelGrid columns="1">
                                  <h:commandLink value="delete"
                                      action="#{flightsController.delete}">
                                      <f:setPropertyActionListener
                                          target="#{flightsController.flight}" value="#{flight}" />
                                  </h:commandLink>
                              </h:panelGrid>
                          </rich:column>
                          <a4j:support reRender="tableStep"
                              action="#{flightsController.takeSelection}"
                              event="onselectionchange" id="table_takeSelection" />
                      </rich:extendedDataTable>
      

       

       

      The extendedDataTableModel is initialized by this code :

       

      private List<Flight> flights = flightsService.getFlights();
      
      public ExtendedTableDataModel<Flight> getExtendedTableDataModel() {
              if(extendedTableDataModel == null) {
                  extendedTableDataModel = new ExtendedTableDataModel<Flight>(new DataProvider<Flight>() {
                      /**
                       * 
                       */
                      private static final long serialVersionUID = -776297803803735490L;
      
                      public Flight getItemByKey(Object key) {
                          for(Flight c : flights){
                              if (key.equals(getKey(c))){
                                  return c;
                              }
                          }
                          return null;
                      }
                      public List<Flight> getItemsByRange(int firstRow, int endRow) {
                          return flights.subList(firstRow, endRow);
                      }
      
                      public Object getKey(Flight item) {
                          return item.getId();
                      }
      
                      public int getRowCount() {
                          return flights.size();
                      }                
      
                  });
              }
              return extendedTableDataModel;
          }
      

       

      Thanks for help

        • 1. Re: extendedDataTableModel update
          aaroniw

          I'm having a similar issue where I modify the underlying data in the ExtendedTableDataModel and it doesn't refresh when it is rerendered.  I put some logging in the DataProvider and the getRowCount is returning the correct number of items, but the getItemsByRange is called with both the first and end row indices as 0.  Is there some way to notify the extendedDataTable that it's table model has been update?  Or notify the ExtendedDataTableModel that it's DataProvider has been updated?

           

          Thanks in advance.

          • 2. Re: extendedDataTableModel update
            aaroniw

            Fixed it... Just need to call the ExtendedTableDataModel.reset() method after the underlying data is altered.