How to count how many occurrences of an attribute in a list are equal to a value? JSF

0

I need to count how many statuses are equal to '1'. I used this to count how many objects I had on the list and it worked. Now I can not count only those with status equal to 1.

<h:outputText value="#{fn:length(cur.listaProdutosManutencao)}" />

This is what I used and it worked.

I tried this below to get the status and it did not work:

<h:outputText value="#{fn:length(cur.listaProdutosManutencao.status eq '1')}" />

I tried this one too, and it did not work:

<h:outputText value="#{fn:join(cur.listaProdutosManutencao.status, '1')}"

Can anyone help me? I would like to follow the first one I did.

    
asked by anonymous 12.09.2018 / 16:35

1 answer

0

However, if you are using JDK 8 you can use list.forEach (action). I vary a method for this.

public Integer totalStatus ( List<ProdutoManutencao> lista, String status){
      Integer  result = 0;
      //validacao para a  lista null ou status.
     for (ProdutoManutencao object : lista) {
         result += object.stattus.equals(status) ? 1 : 0;   
      }
     return result;
  } 
}

In your .xhtml you can call your method. It could be a shorter method that already does this directly in your Bean without having to pass parameters.

<h:outputText value="#{cur.totalStatu( cur.listaProdutosManutencao() ,"1") }" />
    
14.09.2018 / 00:39