jsf - List from managed bean is not showing in faces datatable -
i can't list obtained managed bean show in datatable in jsf.
when debug it, list has 1 element when calls method on bean, page shows no elements in datatable.
the managed bean is:
@managedbean @viewscoped public class mybeanmb { private list<mybean> results = new arraylist<mybean>(); private mybean mybean = new mybean(); @ejb private mybeanservice mybeanservice; public string findmybeans() { results = mybeanservice.findmybeans(mybean); mybean = new mybeans(); if (results != null && !results.isempty()) { return "success"; } facescontext.getcurrentinstance().addmessage(null, new facesmessage("no results found")); return null; }
and form in index.xhtml page looks this:
<h:form> <h:messages /> <h:outputlabel value="nombre: " for="nombre"/> <h:inputtext id="nombre" value="#{mybeanmb.mybean.name}" /> <h:commandbutton value="buscar" action="#{mybeanmb.findmybeans}" /> <h:datatable id="list" value="#{mybeanmb.results}" var="item"> <h:column> <f:facet name="header"> <h:outputtext value="name"/> </f:facet> <h:outputtext value= "#{item.name}" /> </h:column> </h:datatable> </h:form>
what missing?
when return success
in managed bean, jsf navigate success.xhtml view (this assuming haven't set navigation rule in faces-config.xml file) , list should handled in view, not in index.xhtml. in order fix code, change findmybeans
method 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")); }
Comments
Post a Comment