2017-03-01 46 views
0

我試圖在PrimeFaces(5.3)上實現惰性數據表,但它從不呈現表。問題在於惰性模型類上的load()方法永遠不會被調用。該表由String的arrayList構建,其中每個String [](長度爲5)是表中的一行。Primefaces懶惰數據表爲空

視圖(相關的代碼)

<h:form id="formHome"> 
      <p:commandButton process="@this" partialSubmit="true" update="@form" 
       value="obtener tabla" 
       actionListener="#{mbParametros.init}" 
       oncomplete="location.reload();"> 
      </p:commandButton> 
    <p:dataTable id="parametros" 
          selection="#{mbParametros.lazy.seleccionados}" 
          rowKey="#{registro[0]}" value="#{mbParameros.lazy}" var="registro" 
          paginator="true" lazy="true" rows="15" selectionMode="single " 
          paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
          rowsPerPageTemplate="15,30,45" resizableColumns="false" 
          widgetVar="tabla"> 

          <p:ajax event="page" oncomplete="location.reload();" /> 

          <f:facet name="header"> 
           <h:outputText value="Parametros, Fechas y Etiquetas" /> 
          </f:facet> 

          <!-- COLUMNA DE CHECKBOXES --> 
          <p:column selectionMode="multiple" /> 

          <!-- COLUMNA DEL ENTORNO GEOGRAFICO --> 
          <p:column id="col0" headerText="#{mbParametros.lazy.header}"> 

           <h:outputText value="#{registro[0]}" /> 

          </p:column> 

          <!-- COLUMNA DEL TIPO DE PARAMETRO --> 
          <p:column id="col1" headerText="Tipo"> 
           <h:outputText value="#{registro[1]}" /> 
          </p:column> 

          <!-- COLUMNA DEL NOMBRE DEL PARAMETRO --> 
          <p:column id="col2" headerText="Parametro"> 
           <h:outputText value="#{registro[2]}" /> 
          </p:column> 


          <!-- COLUMNA DEL VALOR DEL PARAMETRO --> 
          <p:column id="col3" headerText="Valor"> 
           <h:outputText value="#{registro[3]}" /> 

          </p:column> 


          <!-- COLUMNA DE LA DESCRIPCION DEL PARAMETRO --> 
          <p:column id="col4" headerText="Descripcion"> 
           <h:outputText value="#{registro[4]}" /> 

          </p:column> 


         </p:dataTable> 

</h:form> 

控制器(彈簧控制器,都被配置爲與彈簧3.2.16素)

@Scope("session") 
@Controller("mbParametros") 
public class MBParametros implements Serializable { 

    private static final Logger LOG = LoggerFactory.getLogger(MBParametros.class); 
    private static final long serialVersionUID = 1L; 

    @Autowired 
    private ResourceBundleMessageSource recursos; 

    private LazyDataModel<String[]> lazy; 

    public void init() { 
     LOG.info("ENTRA AL INIT"); 
     this.setLazy(new ModeloLazy(recursos) { 
      private static final long serialVersionUID = 1L; 

     }); 
    } 

    public LazyDataModel<String[]> getLazy() { 
     return lazy; 
    } 

    public void setLazy(LazyDataModel<String[]> lazy) { 
     this.lazy = lazy; 
    } 

懶惰模型類(相關的代碼只)

public class ModeloLazy extends LazyDataModel<String[]> { 
     // ArrayList of Strings that represent all table rows 
    private List<String[]> tabla;  

    public List<String[]> getTabla() { 
     return tabla; 
    } 

    public void setTabla(List<String[]> tabla) { 
     this.tabla = tabla; 
    } 
    // all other fields, getters, setters, init, etc..... 
     // constructor 
public ModeloLazy(ResourceBundleMessageSource recursos) { 
      this.recursos = recursos; 
      this.init(); 
} 

     // load never gets called by the framework, so its an error somewhere else 
     @Override 
public List<String[]> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { 
      this.setRowCount(15); 
      return this.getTabla(); 
     } 

    // init() calls this method for building the table 
    // after execution, tabla is not null nor empty. 
    private void construir(DTOResponse result, DTORequest request) { 
      List<DTORegistro> registros = bsd.join(result, request); //OK 
      for (DTORegistro dtoRegistro : registros) { 
       String tipo; 
       switch(dtoRegistro.getParametro().getTipo()) { 
       case 'p': 
        tipo = "Parametro"; 
        break; 
       case 'e': 
        tipo = "Etiqueta"; 
        break; 
       default: 
        tipo = "Fecha"; 
       } 
       String[] reg = {dtoRegistro.getDto().getNombre() + tipo 
         + dtoRegistro.getParametro().getValor() + dtoRegistro.getParametro().getDescripcion()}; 
       this.getTabla().add(reg); 
      } 

     } 

    } 

回答

0

我的LazyDataModel的實現也不會顯示行,直到我調用LazyDataModel.setRowCount(int rowCount)在我的實現類的構造函數中。

我的<p:dataTable>加載超過16K行,所以我使用頁面選擇時調用load()的分頁程序。 load()根據參數firstpageSize獲取指定行,然後調用setRowCount(int rowCount),然後在DataTable中顯示適當的數據頁面。

+0

這可以在PF展櫃中看到! – Kukeltje