1
嗨,大家好抱歉再次發佈,但這確實是困惑我如何從控制器模型數據視圖
我有一個查詢我可以得到運行,用戶輸入一個字符串,然後應用將在連接到應用程序的數據庫中搜索這個數據,這一點我有工作,但是現在我已經成功運行了queury,我不確定如何從數據中檢索數據並能夠在視圖中使用它h:datatable
當前要做的搜索,這是什麼在視圖中,用戶輸入的faclet頁面
<h:inputText id="search" value="#{userdetailsController.search}" />
<p:commandButton value="Search" action="#{userdetailsController.submit}" ajax="true" />
這則轉到
@Named("userdetailsController")
@SessionScoped
public class UserdetailsController implements Serializable {
@EJB
private String search;
private List<Userdetails> item; // No need for DataModel here.
public String submit() {
item = ejbFacade.searchByString(search);
return ""; //change this !, testing only
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
然後
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
private List userList;
/* trying out a search function */
public List<T> searchByString(String string) {
System.out.println("in SearchByString");
return getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("username", "%" + string + "%").getResultList();
}
它確實在
@Entity
@Table(name = "USERDETAILS")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Userdetails.findAll", query = "SELECT u FROM Userdetails u"),
@NamedQuery(name = "Userdetails.findById", query = "SELECT u FROM Userdetails u WHERE u.id = :id"),
@NamedQuery(name = "Userdetails.findByUsername", query = "SELECT u FROM Userdetails u WHERE u.username = :username")})
搜索我怎麼能一旦這個過程已經完成檢索數據打印出例如控制檯,我需要打電話來做什麼?
非常感謝您的幫助,它被稱爲目前項目的原因是監守我用別的東西的屬性名的項目,然而,當我嘗試你的代碼中,我得到的錯誤 'javax.el.PropertyNotFoundException:本class'Richard.jsfClasses.UserdetailsController $ Proxy $ _ $$ _ WeldClientProxy'沒有屬性'item'。' 看起來它無法找到'item'但它在那裏,有什麼我做錯了 – user2061913
你忘了爲它創建/生成一個getter方法。 – BalusC