0
I have a list that is populated by data from an xml file and another list that is returned from a query in the database. I wonder if it is possible to compare an existing code in these 2 lists. If the codes are equal do not display this element in the datatable.
Example:
Lista 1 (xml): [processo[cod= 123, nome=Diego], processo[cod= 321, nome=Bruno]]
Lista 2 (bd): [processo[cod=321, nome Bruno], processo[cod = 456, nome=josé]]
The code process 321
and name Bruno
exists in both lists, so it is not displayed in the dataTable
Datatable:
Código Nome
123 Diego
456 José
How do I get this result?
Bean:
@ManagedBean(name = "dtBasicView")
@ViewScoped
public class SolicitacoesBean {
private List<Solicitacoes> list;
private List<Solicitacoes> listaFiltrada;
@PostConstruct
public void init() {
// pega a lista com os dados do .xml
try {
list = XmlParserSolicitacoes
.realizaLeituraXML("C:\\Solicitacoes.xml");
System.out.println(list);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Method that returns the database query in a list:
public List<SolicitacoesBD> listar(){
SolicitacoesDAO dao = new SolicitacoesDAO();
List<SolicitacoesBD>lista = dao.listar();
for(SolicitacoesBD s : lista){
System.out.println(s);
}
return lista;
}
My datatable:
<p:dataTable emptyMessage="Nenhum registro encontrado" var="lista"
value="#{dtBasicView.list}"
filteredValue="#{dtBasicView.listaFiltrada}" rows="10"
paginator="true" style="margin-top: 5px;"
rowKey="#{lista.codigoBeneficiario}">
<p:column headerText="Código" filterBy="#{lista.codigoBeneficiario}" style="width:20%" >
<h:outputText value="#{lista.codigoBeneficiario}" />
</p:column>
<p:column headerText="Nome" filterBy="#{lista.nomePessoa}" style="width:45%;"
sortBy="#{lista.nomePessoa}">
<h:outputText value="#{lista.nomePessoa}" />
</p:column>
<p:column headerText="Senha" style="width:10%">
<h:outputText value="#{lista.senha}" />
</p:column>
<p:column headerText="Data Solic." style="width:20%">
<h:outputText value="#{lista.dataSolicitacao}" />
</p:column>
<p:column headerText="Status" style="width:22%" sortBy="#{lista.status}" filterBy="#{lista.status}">
<h:outputText value="#{lista.status}" />
</p:column>
<p:column headerText="Opções" style="width:7%">
<p:commandButton icon="ui-icon-search"
action="#{dtBasicView.abrirDialogo}" process="@this">
<!-- Mandar informação para outra página -->
<f:setPropertyActionListener target="#{dtBasicView.solicitacoes}" value="#{lista}" />
</p:commandButton>
</p:column>
</p:dataTable>
If you use a list
Set
will not remove the repeated ones? or has different attributes?– Maicon Carraro
It has different attributes, I must leave the same attributes?
– DiegoAugusto
A very shoddy solution would be to rotate 2 loops in the list and remove the repeated values.
– Maicon Carraro
But for that all the elements would have to be equal? Or can I just compare the code?
– DiegoAugusto