繁体   English   中英

Primefaces惰性数据表为空

[英]Primefaces lazy data table is empty

我正在尝试在PrimeFaces(5.3)上实现一个懒惰的数据表,但它从未呈现该表。 问题在于,永远不会调用惰性模型类上的load()方法。 该表是根据Strings的arrayList构建的,其中每个String [](长度5)是表中的一行。

查看(相关代码)

<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);
            }

        }

    }

在我在实现类的构造函数中调用LazyDataModel.setRowCount(int rowCount)之前,我的LazyDataModel实现也不会显示行。

我的<p:dataTable>加载超过16,000行,因此我使用了分页器,该分页器在选择页面时调用load() load() first根据参数和pageSize获取指定的行,然后调用setRowCount(int rowCount)然后在DataTable中显示正确的数据页。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM