【问题标题】:Update dataTable (using lazy loading) from another component从另一个组件更新 dataTable(使用延迟加载)
【发布时间】:2011-11-23 08:52:45
【问题描述】:

我在数据表中使用延迟加载和分页,并且工作正常。问题是我在同一个html页面中有一个高级搜索功能,当我点击搜索按钮时,我希望我的dataTable根据我在高级搜索字段中输入的值进行更新(这个功能在@实现987654321@, 代码如下。但是我按钮上的更新属性似乎没有做任何事情,因为没有调用惰性模型的加载方法。所以问题是:我可以以某种方式从模型外部调用惰性模型的加载方法来更新我的数据表吗?

表格:

<h:form id="frmCli">
    <p:commandButton value="Buscar"
                     update="frmCli:panelResultadosDoc"/>
    <h:panelGroup id="panelResultadosDoc">
        <div class="dataTable">     
            <p:dataTable id="documentos"
                         value="#{documentoBuscadorBean.lazyModel}"
                         lazy="true"
                         var="varDocBean"
                         paginator="true"
                         paginatorPosition="bottom"
                         paginatorAlwaysVisible="false"
                         rows="5">           
                <p:column>
                   <f:facet name="header">Código</f:facet>
                   <h:outputText value="#{varDocBean.documento.id}"/>
                 </p:column>                                                         
            </p:dataTable>
        </div>     
    </h:panelGroup>
</h:form>

包含模型的 Bean:

@ManagedBean
@SessionScoped
public class DocumentoBuscadorBean {

   private LazyDataModel<DocumentoBean> lazyModel;

   @SuppressWarnings("serial")
   public DocumentoBuscadorBean() {

      lazyModel = new LazyDataModel<DocumentoBean>() {

      public List<DocumentoBean> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters) { 
            List<DocumentoBean> lazyListDocumentos = new ArrayList<DocumentoBean>();
               try {                  
                  lazyListDocumentos = DaoFactory.getDocumentoDao().buscarLazy(first, pageSize);
             } catch (DocumentoException e) {
                e.printStackTrace();
             }
               return lazyListDocumentos;
           }         
         };            
         lazyModel.setRowCount(DaoFactory.getDocumentoDao().rowCount());
         lazyModel.setPageSize(5);
   }
   public LazyDataModel<DocumentoBean> getLazyModel() {
      return lazyModel;
   }

}

【问题讨论】:

    标签: java jsf primefaces


    【解决方案1】:

    如果我没有遗漏什么,您可以使用操作:

    <p:commandButton value="Buscar"
                     action="#{documentoBuscadorBean.lazyModel.load(0,10,...)}"
                     process="@form"
                     update="frmCli:panelResultadosDoc"/>
    

    最好添加无参数版本的负载,这样您就不会在视图中混合逻辑。如果您由于某种原因不能使用 EL 2.2,这甚至是强制性的(不过我强烈推荐 EL 2.2,它可以为您节省很多丑陋的 f:param 处理)。

    【讨论】:

    • 你不能在jsf中添加这样的参数值!
    • @spauny 请阅读例如stackoverflow.com/questions/3599948/jsf2-action-parameter 并删除这个误导性的反对意见。如果 OP 使用的是 JSF 1,则很容易创建无参数版本的加载。
    • 这取决于 EL 实现。只有 JBoss EL 和 JSP 2.2 EL 能够做到这一点……而且使用 Seam 使这成为可能……使用简单的 JSF + Primefaces 这不可能。除非您编辑帖子并发布添加参数的其他方式,否则无法删除投票...
    【解决方案2】:

    #{varDocBean.documento.id} 是什么意思? varDocBeanDocumentoBean - 所以 documento 是 DocumentoBean 的属性?

    另外,什么 commandButton 什么都不做?我只看到一个 commandButton 但没有操作方法。

    您应该(再次)看看 Primefaces 实验室展示中的 lazy dataTablehttp://www.primefaces.org/showcase-labs/ui/datatableLazy.jsf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多