When you return success
in your managed bean, JSF will navigate to success.xhtml view (this assuming you haven't set a navigation rule in faces-config.xml file) and the list should be handled in this view, not in index.xhtml. In order to fix your code, change your findMyBeans
method to return void
instead of String
.
public void findMyBeans() {
results = myBeanService.findMyBeans(myBean);
myBean = new myBeans();
if (results != null && !results.isEmpty()) {
return;
}
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No results found"));
}