1

I am trying to search a database that I have developed using JSF as the front end technology. I am getting an error saying the following:

Unable to find method [searchContractors] with [0] parameters

Here is the code that I have used. Can anyone tell me if there is something obvious that I am doing wrong because I can't understand why I am getting this error. Thanks for the help.

JSF code

<!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 code

@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;
}   
}
kolossus
  • 20,559
  • 3
  • 52
  • 104
kellzer
  • 131
  • 1
  • 3
  • 18
  • Maybe the wrong EL version is used at runtime? See [How to call a method with a parameter in JSF](http://stackoverflow.com/questions/5273729) – halfbit Mar 28 '14 at 21:42
  • Thanks for your answer but that's not the problem. I am passing parameters successfully in other JSF pages. – kellzer Mar 28 '14 at 21:58
  • Check any attractive difference between those pages and the one in question and/or the used managed-bean. – Omar Mar 28 '14 at 22:03
  • @halfbit may still be correct. JAR clashes generally result in undefined behaviour; it may be working in one instance and fall apart the next. I'd look into the EL versioning at least to eliminate it. Apart from the `` (you should have `` if you don't want js/ajax problems), your code looks ok. Try providing a no-arg version of `searchContractors` and observe – kolossus Mar 30 '14 at 04:20

1 Answers1

0

the following should work:

<ui:param name="countyId" value="#{searchBean.countyId}" />
...
<h:commandButton id="searchContractors" 
    action="#{searchBean.searchContractors(countyId)}">
Angular University
  • 42,341
  • 15
  • 74
  • 81