我正在尝试对产品进行研究。
我的观点是这样的:
<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>
这是 productsScroller.xhtml
OT:我不知道为什么我必须使用来查看更多数据,只是滚动不起作用......
<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>
这是 productsController(@Named 和 @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());
}
}
方法searchProdByFeatures()运行良好,但问题是 dataScroller 不会更新...我知道视图中有问题...但是什么?
还是从控制器更新视图会更好?如何?