jsf - Can't get filtering to work on PrimeFaces DataTable -


i trying use filtering on datatable. whenever table first loads, looks this:

enter image description here

if enter text filter of user name, table looks this:

enter image description here

i expect show dangreen87 since mike.smith not contain "d". displays no user names. im not sure behaviour is?

i have datatable so:

<h:body>     <ui:composition>         <h:panelgroup layout="block" styleclass="messagespanel" rendered="#{socialadvertisermanagedbean.displaysearch}" >             <p:datatable                  resizablecolumns="true"                 var="account"                  value="#{searchmanagedbean.accountstodisplay}"                  scrollable="true"                 paginator="true"                 rows="10"                 rowkey="#{account.id_value}"                 emptymessage="no accounts found given criteria"                 widgetvar="searchtable"                 filteredvalue="#{searchmanagedbean.filteredaccounts}">                 <f:facet name="header">                     #{searchmanagedbean.iscompany ? 'company' : 'social advertisers'}                 </f:facet>                 <p:column headertext="image">                     <p:graphicimage value="/dbimages/#{accountmanagedbean.getimageid(account)}" width="25" height="25"/>                 </p:column>                  <c:if test="#{searchmanagedbean.iscompany}" >                     <p:column headertext="company name">                         <h:outputlabel value="#{accountmanagedbean.getcompany(account).name}" />                     </p:column>                 </c:if>                  <c:if test="#{not searchmanagedbean.iscompany}" >                      <p:column id="usernamecolumn" filterby="#{account.username}" filtermatchmode="contains">                         <f:facet name="header">                             <h:outputlabel value="user name"/>                         </f:facet>                         <h:outputlabel value="#{account.username}" />                     </p:column>                  </c:if>              </p:datatable> 

my backing bean looks so:

@managedbean @viewscoped public class searchmanagedbean implements serializable {      private boolean iscompany;     private account selectedaccount;       @ejb     private accountdao accountdao;      @ejb     private socialadvertiserdao socialadvertiserdao;      @ejb     private companydao companydao;      private list<account> filteredaccounts;      @postconstruct     public void init()     {         iscompany = true;     }      public list<account> getaccountstodisplay()     {         list temp;         if(iscompany)         {             temp = companydao.findall();         }         else         {             temp = socialadvertiserdao.findall();         }         return temp;     }      public list<account> getfilteredaccounts() {         return filteredaccounts;     }      public void setfilteredaccounts(list<account> filteredaccounts) {         this.filteredaccounts = filteredaccounts;     }       public boolean getiscompany() {         return iscompany;     }      public void setiscompany(boolean iscompany) {         this.iscompany = iscompany;     }      .... 

those jstl <c:if> tags bound view scoped bean property culprit.

<c:if test="#{not searchmanagedbean.iscompany}" >     <p:column id="usernamecolumn" filterby="#{account.username}" filtermatchmode="contains">         ...     </p:column> </c:if> 

long story short, read @viewscoped fails in taghandlers , jstl in jsf2 facelets... makes sense? in nutshell, causes view scoped bean recreated on every single http request , therefore complete reset of bean's state across filtering , sorting ajax requests.

this @viewscoped+taghandler issue solved since mojarra 2.1.18. basically, you'd need upgrade @ least mojarra 2.1.18 (it's @ 2.1.25). however, after not canonical approach. should use rendered attribute of <p:column> that.

<p:column id="usernamecolumn" filterby="#{account.username}" filtermatchmode="contains" rendered="#{not searchmanagedbean.iscompany}">     ... </p:column> 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -