我得到了以下JSF构造:
index.xhtml:
<h:form>
<h:commandButton class="btn btn-success pull-left left-puffer right-puffer" value="Test" action="#{bean.debugCode()}" />
</h:form>
bean.java =>在视图和DataBaseController之间使用的bean
package db_container;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "bean")
@SessionScoped
public class Bean {
/*
* VARIABLES
*/
// Database
private DataBaseController xy = null;
/*
* CONSTRUCTOR
*/
public Bean() throws Exception {
this.xy = new DataBaseController();
}
/*
* METHODS
*/
public void debugCode() {
xy.DebugtoDB("DEBUG", "hallo", "welt", "neu");
}
}
堆栈跟踪:
WARNING: #{bean.debugCode()}:
javax.el.MethodNotFoundException: /index.xhtml @330,139 action="
{bean.debugCode}": Method not found:
db_container.Bean@fda7ea.debugCode()
javax.faces.FacesException: #{bean.debugCode()}: javax.el.MethodNotFoundException: /index.xhtml @330,139 action="#{bean.debugCode}": Method not found: db_container.DetailsManager@fda7ea.debugCode()
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:110)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
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:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at net.sourceforge.spnego.SpnegoHttpFilter.doFilter(SpnegoHttpFilter.java:318)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
现在,当我启动视图并单击按钮时,将出现异常。不幸的是,对我来说这似乎不合逻辑,因为bean中有可以调用的函数。
我在做什么错了?
答案 0 :(得分:1)
您的方法需要一个布尔值:
public void debugCode(Boolean test) {
xy.DebugtoDB("DEBUG", "hallo", "welt", "neu");
}
在这种情况下,xhtml中的方法调用实际上必须像这样传递true
或false
值:
<h:form>
<h:commandButton class="btn btn-success pull-left left-puffer right-puffer" value="Test" action="#{bean.debugCode(true)}" />
</h:form>