为什么JSF对Hibernate控制器的调用返回javax.el.MethodNotFoundException



我试图通过Hibernate执行对mySQL数据库的查询,为此我开发了一个简单的JSF页面来介绍两个单词并通过这些字段进行搜索,但是当我试图执行使查询的方法时,我遇到了一个异常:javax.el.MethodNotFoundException

JSF页面:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <title>Plans search</title>
</h:head>
<h:body>
    <h3>Plan Search</h3>
    <h:form>
        <h:selectOneRadio id="searchBy" value="#{myController.searchBy}">
            <f:selectItem itemLabel="By User" itemValue="User Name"></f:selectItem>
            <f:selectItem itemLabel="By Plan" itemValue="Plan Name"></f:selectItem>
        </h:selectOneRadio>
        <h:inputText label="Name" id="name" value="#{myController.name}"></h:inputText>
        <h:inputText label="Surname" id="surname" value="#{myController.surname}"></h:inputText>
        <h:commandButton id="search" type="submit" value="Search" action="#{myController.userPlans}"></h:commandButton>
    </h:form>
    <div><h:outputText value="#{myController.name} was invited to the following plans"></h:outputText></div>
    <h:dataTable id="plansid" value="#{myController.userPlans}" var="plans" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
        <h:column>
            <f:facet name="header">
                <h:outputText value="Plans Name"></h:outputText>
            </f:facet>
            <h:outputText value="#{plans.planName}"></h:outputText>
        </h:column>
    </h:dataTable>
</h:body>

和myController的代码是:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@ManagedBean
@SessionScoped
public class MyController {
MyHelper helper;
DataModel listUSer;
private DataModel userPlans;
private String name;
private String surname;
Users user;
private String searchBy;
/**
 * Creates a new instance of myController
 */
public MyController() {
    helper = new MyHelper();
}
public MyController(String name, String surname) {
    helper = new FeverHelper();
    this.name = name;
    this.surname = surname;
}
void recreateModel() {
    setUserPlans(null);
}
/**
 * @return the searchBy
 */
public String getSearchBy() {
    return searchBy;
}
/**
 * @param searchBy the searchBy to set
 */
public void setSearchBy(String searchBy) {
    this.searchBy = searchBy;
}
/**
 * @return the name
 */
public String getName() {
    return name;
}
/**
 * @param name the name to set
 */
public void setName(String name) {
    this.name = name;
}
/**
 * @return the surname
 */
public String getSurname() {
    return surname;
}
/**
 * @param surname the surname to set
 */
public void setSurname(String surname) {
    this.surname = surname;
}
/**
 * @return the userPlans
 */
public DataModel getUserPlans() {
    if (userPlans == null) {
        setUserPlans(new ListDataModel(helper.getUserPlans(getName(), getSurname())));
    }
    return userPlans;
}
/**
 * @param userPlans the userPlans to set
 */
public void setUserPlans(DataModel userPlans) {
    this.userPlans = userPlans;
}

}

显然定义得很好,不是吗?

我只是在处理index.xhtml文件,没有模板,或其他填充的东西。

您没有指定失败的组件。乍一看,我认为这是

<h:commandButton id="search" type="submit" value="Search" action="#{myController.userPlans}"></h:commandButton>

(如果不是,这是你的错,因为没有提供你的问题的详细描述)。

一个动作方法不是一个属性,所以你需要在你的控制器类中定义这些方法之一:

public String userPlans()...
public void userPlans()...  // no navigation

您的XHTML中的搜索命令按钮指向#{myController。但是bean上没有userPlans()

的操作方法

相关内容

  • 没有找到相关文章

最新更新