我在尝试使用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)
我的托管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 :(得分:2)
action="#{travelBean.travelInfo}"
是一种操作方法。在搜索适当的方法时,只有value方法将travelInfo从EL表达式转换为getTravelInfo()。在操作方法中,预计travelInfo()方法应该存在于托管bean中,但它不是。
答案 1 :(得分:2)
以防万一,如果您没有导入正确的库,可能会发生相同类型的问题。有时您的IDE可以自动导入:“ import java.awt.event.ActionEvent;”而不是“ import javax.faces.event.ActionEvent;”从而导致“相同”问题。将无法找到该方法。