2016-12-25 121 views
-2

在使用JSF嘗試簡單應用程序時出現錯誤。javax.el.MethodNotFoundException:未找到方法:JSF

javax.el.MethodNotFoundException: Method not found: [email protected]() 
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) 

我的管理bean是:

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

和我的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> 

我已經看了看其他問題,並試圖回答,但沒有奏效。 任何幫助是高度讚賞。提前致謝!

+0

答案是對的,但是好奇心,stacktrace中的錯誤部分不清楚?對我來說這是非常具體的。它說'未找到方法:[email protected]()',並且因爲在你的bean中沒有這樣的方法叫'travelInfo(),你會得到這個錯誤。爲什麼沒有右側的「相關」Q/A有幫助?幾個包含良好的答案 – Kukeltje

+0

我正在使用'action =「#{travelBean.travelInfo}」'因爲我認爲它會轉換爲'getTravelInfo',因爲它會在值的方法。 @Artur明確提到的一點。這是我不明白stacktrace – Srikar

回答

3

action="#{travelBean.travelInfo}"是一種動作方法。當搜索適當的方法時,只有值方法將travelInfo從EL表達式轉換爲getTravelInfo()。在action方法中,travelInfo()方法預計會出現在託管bean中,但事實並非如此。

+0

非常感謝!它爲我工作 – Srikar