当filterBy是一个对象列表时,是否可以过滤p:dataTable?

时间:2018-04-17 21:57:46

标签: java primefaces

我正在使用Primefaces的组件p:dataTable,我在排序对象列表方面遇到了麻烦。

我有一个电子邮件列表,在这个列表中我有另一个列表,上面有他们的电子邮件别名。这是我的代码:

public class Email {

    private String idGoogle;
    private String email;

    public Email() {
    }

    public Email(String idGoogle, String email) {
        this.idGoogle = idGoogle;
        this.email = email;
    }  
    
    public String getIdGoogle() {
        return idGoogle;
    }

    public void setIdGoogle(String idGoogle) {
        this.idGoogle = idGoogle;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
 }

public class EmailSector extends Email implements Cloneable {

    private Sector sector = new Sector();
    private String password;
    private String domain;
    private String description;
    private List<Email> aliasList = new ArrayList<>();
    private List<EmailSector> emailSectorList = new ArrayList<>();


    public EmailSector() {
    }

   ...

            <h:panelGroup id="emailsTable" >
                <div class="emailsTable" >
                    <p:dataTable id="filterTable" var="item" value="#{emailSectorBean.sessionBean.itemPagina.emailSectorList}" 
                                 widgetVar="dataWidget" 
                                 emptyMessage="Nenhum registro encontrado com os dados buscados.">

                        <p:column filterBy="#{item.email}" headerText="E-Mail" filterMatchMode="contains"
                                  filterValue="#{emailSectorBean.sessionBean.filtroAlteracao}">
                            <h:outputText value="#{item.email}" />
                        </p:column>
                        <p:column filterBy="#{item.description}" headerText="Descrição" filterMatchMode="contains">
                            <h:outputText value="#{item.description}" />
                        </p:column>
                        <p:column filterBy="#{item.sector.description}" headerText="sector" filterMatchMode="contains">
                            <h:outputText value="#{item.sector.description}" />
                        </p:column>
                        <p:column headerText="Alias" filterBy="#{item.listaAlias}" filterMatchMode="contains">
                            <h:dataTable var="alias" value="#{item.listaAlias}" >
                                <p:column>
                                    <h:outputText value="#{alias.email}"/>
                                </p:column>
                            </h:dataTable>
                        </p:column>                        
                    </p:dataTable>
                </div>
            </h:panelGroup>    

此时:

                        <p:column headerText="Alias" filterBy="#{item.aliasList}" filterMatchMode="contains">
                            <h:dataTable var="alias" value="#{item.aliasList}" >
                                <p:column>
                                    <h:outputText value="#{alias.email}"/>
                                </p:column>
                            </h:dataTable>
                        </p:column> 

我打印了电子邮件部门的所有别名。问题是aliasList的类型是Email ...所以我想知道是否可以将filterBy与List一起使用,我该如何才能使用它?

由于

1 个答案:

答案 0 :(得分:1)

我通过覆盖toString方法解决了这个问题,就像这样:

&#13;
&#13;
    @Override
    public String toString() {
        return this.email;
    }
&#13;
&#13;
&#13;

然后我在filterBy属性中调用了toString方法:

&#13;
&#13;
<p:column headerText="Alias" filterBy="#{item.aliasList.toString()}" filterMatchMode="contains">
   <h:dataTable var="alias" value="#{item.aliasList}" >
      <p:column>
        <h:outputText value="#{alias.email}"/>
      </p:column>
   </h:dataTable>
</p:column> 
&#13;
&#13;
&#13;

工作得很好!