2

I'm using lazy loading with pagination in a dataTable, and works fine. The problem is that I have an advanced search functionality in the same html page, and when I click on the search button, I want my dataTable to be updated according to the values I entered in the advanced search fields (this functionality is implemented at DaoFactory.getDocumentoDao().buscarLazy(first, pageSize), the code is below. But the update attribute at my button doesn't seem to do anything becouse the load method of the lazy model is not called. So the question is: can I somehow call the load method of the lazy model from outside of the model in order to have my dataTable updated?

FORM:

<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 CONTAINING THE MODEL:

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

}
Reporter
  • 3,897
  • 5
  • 33
  • 47
jbn1981
  • 73
  • 2
  • 9

2 Answers2

2

If I'm not missing something, you could just use action:

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

It would be better to add parameterless version of load so you don't mix logic in your view. This is even mandatory if you cannot use EL 2.2 for some reason (I strongly recommend EL 2.2 though, saves you a lot of ugly f:param handling).

mrembisz
  • 12,722
  • 7
  • 36
  • 32
  • You cannot add param values like this in jsf! – spauny Nov 23 '11 at 09:46
  • @spauny please read for example http://stackoverflow.com/questions/3599948/jsf2-action-parameter and remove this misleading downvote. If OP is using JSF 1, it's easy enough to create parameter-less version of load. – mrembisz Nov 23 '11 at 10:16
  • That depends on the EL implementation. Only JBoss EL and JSP 2.2 EL is capable of doing this...Also using Seam makes this possible...With simple JSF + Primefaces this isn't possbile. The vote cannot be removed unless you edit your post, and post the other way of adding params... – spauny Nov 23 '11 at 10:37
0

What does it mean #{varDocBean.documento.id}? varDocBean is a DocumentoBean - so documento is a property of DocumentoBean?

Also, what commandButton doesn't do anything? I see only one commandButton but without action method.

You should take a look(again) at the lazy dataTable in Primefaces lab showcase: http://www.primefaces.org/showcase-labs/ui/datatableLazy.jsf

spauny
  • 4,976
  • 9
  • 44
  • 61