-1

我正在尝试通过 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 文件,没有模板或其他填充内容。

提前致谢。

4

2 回答 2

1

您的 XHTML 中的搜索命令按钮指向 #{myController.userPlans} 但您的 bean 上没有名为 userPlans() 的操作方法

于 2013-06-13T11:57:34.670 回答
1

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

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

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

action 方法不是属性,因此您需要在控制器类中定义以下方法之一:

public String userPlans()...

public void userPlans()...  // no navigation
于 2013-06-13T11:58:01.267 回答