Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to execute a query to a mySQL database through Hibernate, for that I've developed a simple JSF page to introduce two words and search by these fields, but when I try to execute the method which make the query, I go an exception: javax.el.MethodNotFoundException

Here is the JSF page:

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

and the code for myController is:

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;
}

}

Appareantly is well defined, isn't it?

I'm just working over the index.xhtml file, without templates, or other padding stuff.

Thanks in advance.

share|improve this question

2 Answers

up vote 1 down vote accepted

You do not specify the component that fails. From a glance, I think it is the

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

(if it is not, it is your fault by no providing a detailed description of your problem).

An actio method is not a property, so you need one of these methods defined in your controller class:

public String userPlans()...

public void userPlans()...  // no navigation
share|improve this answer
I think both of you are wrong, because that call myController.userPlans has to call automatically to the getter method for that field. So If I have a field named "userPlans" and I have defined the getter and setter, that call, myController.userPlans should run the getUserPlans. @SJuan76, you are right that component is which it fails. – Joe Lewis 8 hours ago
Not for an action method. You are thinking about property EL expressions, which are a different thing. – SJuan76 8 hours ago
Sorry for that. So could you guide me to fix the error please? I'd thank that. Because I thought that it was well-coded... – Joe Lewis 8 hours ago
Define the function as explained in my post. You still need the getUserPlans so your page can get the property to show it. – SJuan76 8 hours ago
Ok, I understood how JSF works at least for my example. ;) Thanks a lot, this is the right answer. – Joe Lewis 8 hours ago
show 2 more comments

Your search command button in your XHTML is pointing to #{myController.userPlans} but there is no action method on your bean called userPlans()

share|improve this answer
Do your lookup logic in a method called public void userPlans(). Then create the datamodel from the results and set it – zargarf 8 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.