i'm trying to implement a research of products.
My view is something like this:
<h:form>
<p:layoutUnit position="center">
<ui:include src="/Desktop/Users/Include/featureCheckbox.xhtml"/>
</p:layoutUnit>
<p:layoutUnit position="south" style="border: 0px">
<p:commandButton value="Search"
actionListener="#{productsController.searchProdByFeatures()}"
oncomplete="listProd.show();"/>
</p:layoutUnit>
</h:form>
<p:panel widgetVar="listProd" >
<ui:include src="/Desktop/Users/Include/productsScroller.xhtml"/>
</p:panel>
this is productsScroller.xhtml
OT: i don't know why i have to use to view more data, simply scroll doesn't work...
<h:form prependId="false">
<p:dataScroller value="#{productsController.items}" var="item" chunkSize="10">
<f:facet name="header">
Scroll Down to Load More Wheelchair
</f:facet>
<h:panelGrid columns="1" style="width:100%" >
<p:outputPanel>
<h:outputText value="#{item.name}" style="font-weight: bold"/>
</p:outputPanel>
</h:panelGrid>
<f:facet name="loader">
<p:commandButton type="button" value="View More" />
</f:facet>
</p:dataScroller>
</h:form>
and this is productsController (@Named and @ViewScoped)
...
private Collection<Product> items;
private Collection<Product> selectedItems;
public Collection<Product> getSelectedItems() {
return selectedItems;
}
public void setSelectedItems(Collection<Product> selectedItems) {
this.selectedItems = selectedItems;
}
public Collection<Product> getItems() {
if (items == null) {
items = this.ejbFacade.findAll();
}
System.out.println(items.size());
return items;
}
public void setItems(Collection<Product> items) {
this.items = items;
}
public void searchProdByFeatures (){
List<Product> items= (List<Product>) getItems();
List<Product> newItems;
Collection<Feature> featuresCollection = featureController.getSelectedItems();
List<Feature> selectedFeatures = new ArrayList<>(featuresCollection);
System.out.println(selectedFeatures.size()); //just for debug
try {
for (Feature selectedFeature : selectedFeatures) {
String msg=(selectedFeature.getName()+" / ");
System.out.println(selectedFeature.getName());
}
newItems=productFacade.findProdByFeatures(selectedFeatures, items);
System.out.println("Searched product are "+newItems.size()); //just for debug
setItems(newItems);
System.out.println("New items are "+getItems().size()); //just for debug
} catch (NotFoundException e) {
setItems(null);
JsfUtil.addErrorMessage(e.getMessage());
}
}
the method searchProdByFeatures() works well but the problem is that the dataScroller won't update... i know there is something wrong in the view... but what?
or it'll be better to update the view from controller? how?
Edit your code to upadate the dataScroller by adding update="yourIddataScroller"
<p:commandButton value="Search"
actionListener="#{productsController.searchProdByFeatures()}"
oncomplete="listProd.show();" update="yourIddataScroller"/>