1
我想搜索一個我已經使用JSF開發的數據庫作爲前端技術。我收到一個錯誤說以下內容:爲什麼我在我的JSF頁面出現這個錯誤?
找不到方法[searchContractors]與[0]參數
這裏是我使用的代碼。任何人都可以告訴我,如果有什麼明顯的,我做錯了,因爲我不明白爲什麼我得到這個錯誤。謝謝您的幫助。
JSF代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>Search</title>
</head>
<body>
<h:form id="searchForm">
<H2>Search</H2>
<H4>Please select the county that you live in.
</H4>
<table>
<tr>
<td><h:outputLabel for="county">
<h:outputText id="countyLabel" value="County" />
</h:outputLabel></td>
<td><h:selectOneMenu id="countyName"
value="#{searchBean.countyId}">
<f:selectItems value="#{registerBean.counties}" var="county"
itemLabel="#{county.name}" itemValue="#{county.id}" />
</h:selectOneMenu></td>
</tr>
<tr>
<td><h:commandButton id="searchContractors"
action="#{searchBean.searchContractors(searchBean.countyId)}">
<h:outputText value="Search Contractors" />
</table>
</h:form>
</body>
</html>
Java代碼
@ManagedBean
@SessionScoped
public class SearchBean implements Serializable {
private static final long serialVersionUID = -2107387060867715013L;
private static final String PERSISTENCE_UNIT_NAME = "NeedABuilderUnit";
private static EntityManagerFactory factory;
private int countyId;
public List<BusinessAccount> searchContractors(int countyId) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
List<BusinessAccount> contractorList = new ArrayList<BusinessAccount>();
em.getTransaction().begin();
Query myQuery = em.createQuery("SELECT u FROM BusinessAccount u WHERE u.county.id=:CountyId");
myQuery.setParameter("CountyId", countyId);
contractorList=myQuery.getResultList();
em.getTransaction().commit();
em.close();
return contractorList;
}
public int getCountyId() {
return countyId;
}
public void setCountyId(int countyId) {
this.countyId = countyId;
}
}
也許錯了EL版本在運行時使用?請參閱[如何使用JSF中的參數調用方法](http://stackoverflow.com/questions/5273729) – halfbit
感謝您的回答,但這不是問題。我正在其他JSF頁面成功傳遞參數。 – kellzer
檢查這些頁面與正在討論的頁面和/或使用的管理bean之間的吸引力差異。 – Omar