You can save your List in a class variable, give it a getter and (maybe) a setter. Declare searchByString
method as void
and call it with let's say a (provided you are using PrimeFaces):
<p:commandLink update="@form" process="@this" action="#{myBean.searchByString}">
myBean:
public void searchByString(String string) {
userList = getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("username", "%" + string + "%").getResultList();
}
provided your table sits in a form that you just updated you could display the List
in it.
<p:dataTable var="user" value="#{myBean.userList}">
<p:column headerText="Name">
<h:outputText value="#{user.name}" />
</p:column>
</p:dataTable>