sorry if this is a poor question but this one feature have been driving me mad for days so i thought id post it here to see if you guys can help me
basically all i want to do from a jsf page have the user search a user and for me to return all the details
<h:form id="searchForm">
<h:outputLabel value="Search: " style="font-weight:bold" />
<h:inputText id="search" value="#{userdetailsController.search}" />
<h:commandButton value="Search" action="index"/>
</h:form>
that is the jsf page, working fine
it calls my userdetailsController class
@Named("userdetailsController")
@SessionScoped
public class UserdetailsController implements Serializable {
private Userdetails current;
private DataModel items = null;
@EJB
private Richard.beans.UserdetailsFacade ejbFacade;
private PaginationHelper pagination;
private int selectedItemIndex;
private String search;
public String getSearch() {
System.out.println("inGetSearch");
return search;
}
public void setSearch(String search) {
this.search = search;
}
......
a contactsService class
@Stateless
public class ContactsService {
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
@EJB
private UserdetailsFacade cf;
public List<Userdetails> searchByString(String string) {
return cf.searchByString(string);
}
public List<Userdetails> getAllPersons() {
return cf.findAll();
}
}
an AbstractFacade class
/* trying out a search function */
public List<T> searchByString(String string) {
System.out.println("in SearchByString");
return getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("string", "%" + string + "%").getResultList();
}
and the Userdetails class with the query i am trying to search
@NamedQuery(name = "Userdetails.findByUsername", query = "SELECT u FROM Userdetails u WHERE u.username = :username")})
currently only the getters and settings are working in Getsearch
how can i make this work as i have spent days on this feature and are still no closer, sorry this is my first time at this
thanks guys
EDIT
would adding
public List<Userdetails> getAllPersons() {
if (search == null) {
return cs.getAllPersons();
}
return cs.searchByString(search);
}
in the UserdetailsController be enough ?