1

I am getting error while trying a simple application with JSF.

javax.el.MethodNotFoundException: Method not found: com.jsf.training.beans.TravelBean@4b6b8628.travelInfo()
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

My managed bean is :

@ManagedBean (name="travelBean")
@SessionScoped
public class TravelBean {

private int index = 0;
private String source;
private String destination;
private Date date;
java.sql.Date sqlDate;
private boolean visible = false;

public boolean isVisible() {
    return visible;
}
public void setVisible(boolean visible) {
    this.visible = visible;
}
public TravelBean() {

}
public String getSource() {
    return source;
}
public void setSource(String source) {
    this.source = source;
}
public String getDestination() {
    return destination;
}
public void setDestination(String destination) {
    this.destination = destination;
}
public Date getDate() {
    return date;
}
public void setDate(Date date) {
    this.date = date;
}

public int getIndex() {
    return index;
}

public void setIndex(int index) {
    this.index = index;
}

public void getDateInSql() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.format(date);
    sqlDate = new java.sql.Date(date.getTime());
}
public void getTravelInfo() throws SQLException {
    setVisible(true);
    /*SearchServiceImpl search = new SearchServiceImpl();
    search.searchTrainsService(travelBean);*/
    System.out.println("********** in travel Bean :" +source +destination +date);
    TrainBean tb = new TrainBean();
    tb.getTrainsList(source,destination,sqlDate);
}

and my xhtml :

<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"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
<h:outputStylesheet library="css" name="resources/css/table-style.css"  />
</h:head>
<h:body>
<h:form>
<p:growl id="message"></p:growl>
<p:tabView activeIndex="#{travelBean.index}" dynamic="true" effect="fade" effectDuration="fast">
     <p:tab title="Trains">

        <h:form>
            <h:outputText value="Source"/>:<h:inputText id="source" value="#{travelBean.source}"></h:inputText>
            <h:outputText value="Destination"/>:<h:inputText id="destination" value="#{travelBean.destination}"></h:inputText>
            <h:outputText value="Date"/>:<p:calendar id="date" value="#{travelBean.date}"></p:calendar>
            <h:commandButton value="Search Trains" update="table-wrapper" action="#{travelBean.travelInfo}" actionListener="#{travelBean.travelInfo}" > 
                <!-- <f:ajax execute="@this source destination date" render="output" /> -->
                 <f:attribute name="source" value="#{travelBean.source}"/>
                 <f:attribute name="destination" value="#{travelBean.destination}"/>
                 <f:attribute name="date" value="#{travelBean.date}"/>
            </h:commandButton>
           <h2><h:outputText id="output" value="#{travelBean.source} #{travelBean.destination} #{travelBean.date}"/></h2> 
        </h:form>

    </p:tab> 
    <p:tab title="Flights">
        <h1>Search flights by routes</h1>
         <h:form>
            <h:outputText value="Source"/>:<h:inputText id="source" value="#{travelBean.source}"></h:inputText>
            <h:outputText value="Destination"/>:<h:inputText id="destination" value="#{travelBean.destination}"></h:inputText>
            <h:outputText value="Date"/>:<h:inputText id="date" value="#{travelBean.date}"></h:inputText>
            <h:commandButton value="Search Flights" >
                <f:ajax execute="@form" render="output" />
            </h:commandButton>

            <h2><h:outputText id="output" value="#{travelBean.source}"/>        </h2>
         </h:form> 

    </p:tab>
</p:tabView>


</h:form>

</h:body>

</html>

I have looked at the other questions, and tried the answer but nothing worked. Any help is highly appreciated. Thanks in advance!

Srikar
  • 113
  • 1
  • 1
  • 12
  • The answer is right, but but of curiosity, what part of the error in the stacktrace is not clear? To me it is VERY specific. It says `Method not found: com.jsf.training.beans.TravelBean@4b6b8628.travelInfo()` and since there is no such method called 'travelInfo() in your bean you get this error. And why did non of the 'related' Q/A on the right help? Several contain the good answer – Kukeltje Dec 25 '16 at 14:27
  • 1
    I was using `action="#{travelBean.travelInfo}"` as i thought that would convert to `getTravelInfo` as it would in value methods. The point which @Artur mentioned clearly. That is where i was not understanding the stacktrace – Srikar Dec 26 '16 at 03:53

2 Answers2

6

Just in case the same kind of problem might happen if you are not importing the right library. Sometimes your IDE can autoimport: "import java.awt.event.ActionEvent;" instead of "import javax.faces.event.ActionEvent;" and thus causing the "same" issue. It will not be able to find the method.

Dan Ortega
  • 1,679
  • 17
  • 13
  • #12 in https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Aug 23 '18 at 18:14
4

action="#{travelBean.travelInfo}" is an action method. Only value methods converts travelInfo from EL expression to getTravelInfo() when searching for appropriate method. In action method exactly travelInfo() method is expected to be present in your managed bean, but it isn't.

Artur Skrzydło
  • 1,135
  • 18
  • 37