I am trying to implement a mahout based recommender system. I am not able to display the results on a jsf page.
@ManagedBean(name="similarvaluerecommender") @ViewScoped
public class SimilarValueRecommender implements Serializable { private List recommendedItems;
@PostConstruct
public void init() {
this.recommendedItems = new ArrayList<>();
DataModel dm;
try {
dm = new FileDataModel(new File("Dataset/userdata.csv"));
//ItemSimilarity sim = new LogLikelihoodSimilarity(dm);
TanimotoCoefficientSimilarity sim = new TanimotoCoefficientSimilarity(dm);
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(dm, sim);
int x=1;
for(LongPrimitiveIterator items = dm.getItemIDs(); items.hasNext();) {
long itemId = items.nextLong();
List<RecommendedItem>recommendedItems1 = recommender.mostSimilarItems(itemId, 10);
this.recommendedItems.addAll(recommendedItems1);
x++;
}
} catch (TasteException ex) {
Logger.getLogger(SimilarValueRecommender.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex) {
Logger.getLogger(SimilarValueRecommender.class.getName()).log(Level.SEVERE, null, ex);
}
}
//getter and setter...
public List<RecommendedItem> getRecommendedItems(){
return recommendedItems;
}
public void setList(List<RecommendedItem> recommendedItems) {
this.recommendedItems=recommendedItems;
}
}
I would like to display the results of this page on a jsf page in the form of a table. This is the view
<ui:composition template="WEB-INF/commonlayout.xhtml">
<ui:define name="content">
<h:form>
hi
<h:dataTable id="similarvaluestable" value="#{similarvaluerecommender.recommendedItems}" var="recommendedItem">
<h:column>
#{recommendedItem.itemID}
</h:column>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>