I have a page with some products and I want to filter with some params, this is how I show that products:
<h:panelGroup id="productos" layout="block">
<ui:repeat value="#{tipoBean.productos}" var="prod">
<div class="producto" style="width: 245px; height: 200px; float: left; text-align: center;">
<h3><h:outputText value="#{prod.nombre}" /></h3>
<h:link outcome="producto">
<h:graphicImage library="img" name="imagen.png" />
<f:param name="marca" value="#{categoriaBean.marca}" />
<f:param name="tipo" value="#{categoriaBean.tipo}" />
<f:param name="prod" value="#{prod.nombre}" />
</h:link>
</div>
</ui:repeat>
</h:panelGroup>
I also have a block with some checkboxes, and I want to filter the results when I choose any of them, this is the block:
<div id="filtroTipo" class="filtroTipo" style="width: 220px; height: 860px; float: left; text-align: center;">
<h2>Filtrar Resultados</h2>
<h:form>
<h3>Sistema Operativo</h3>
<p:selectManyCheckbox value="#{tipoBean.sistOpsSelected}" layout="pageDirection">
<f:selectItems value="#{tipoBean.sistOps}" />
<p:ajax listener="#{tipoBean.filtrarProductos}" update="productos" />
</p:selectManyCheckbox>
</h:form>
</div>
And now is when comes the big doubt, I don't know how to filter, well there are many ways to do that, but I mean, what is the appropiate way to do that? What I have to use? EntityManager? PreparedStatement? Only remove the items I don't want to use?
I tried to use EntityManager injected, but it doesn't work.
Greetings.
Usually in order to filter results you make a new query to the database with the appropiate filters. Especially when you have to read too many rows so instead of reading them all at once you paginate and start reading 20 rows per page or so. in those cases, the only way you have is to apply filters in the DB query, because you don't have all the entities in the managed bean, only the current page. I know this is not your scenario (at least for now) because you are not paginating, but I mention it because in the future you might have to paginate, and this is how it's done