一个非常简单的问题,但我无法解决,
我的 xhtml 页面有
<p:commandButton action="#{NaviagationBean.buttonToUploadText}" value="Submit" icon ="ui-icon-arrowstop-1-n"/>
我想从我的 NavigationBean 中调用代码.java存储在 richard.fileupload 中调用此代码:
public String buttonToUploadText() {
System.out.println("buttonToUploadText invoked");
return "/upload/uploadText.xhtml";
}
基本上我需要在我的XHTML中调用什么操作?
由于代码ATM显示此错误:
WARNING: #{NavigationBean.buttonToUploadText}: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
javax.faces.FacesException: #{NavigationBean.buttonToUploadText}: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
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:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:95)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 36 more
Caused by: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 37 more
编辑
当我这样做时,它工作正常:
<p:commandButton action="#{userBean.buttonToUploadText}" value="Submit" icon ="ui-icon-arrowstop-1-n"/>
使用用户豆中的代码.java
堆栈跟踪为:
WARNING: #{NavigationBean.buttonToUploadText}: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
javax.faces.FacesException: #{NavigationBean.buttonToUploadText}: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
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:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:95)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 36 more
Caused by: javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,130 action="#{NavigationBean.buttonToUploadText}": Target Unreachable, identifier 'NavigationBean' resolved to null
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 37 more
编辑2:
<p:commandButton action="#{NaviagationBean.buttonToUploadText()}" value="Submit" icon ="ui-icon-arrowstop-1-n" ajax="False"/>
给了我相同的堆栈跟踪,但现在将我带到一个页面
javax.el.PropertyNotFoundException: /GUI/index.xhtml @61,146 action="#{NaviagationBean.buttonToUploadText()}": Target Unreachable, identifier 'NaviagationBean' resolved to null
消息"目标不可达,标识符"NavigationBean"解析为 null 表示 JSF 框架找不到您的托管 Bean。确保你已经按如下方式编写了你的 bean:
@ManagedBean(name="NavigationBean")
@RequestScope
public class NavigationBean {
public NavigationBean() {
}
public String buttonToUploadText() {
System.out.println("buttonToUploadText invoked");
return "/upload/uploadText.xhtml";
}
//other methods...
}
或者如果您使用 CDI
@Named("NavigationBean")
@RequestScope
public class NavigationBean {
//...
}
另一种解决方案是在EL中使用navigationBean
而不是NavigationBean
:
<p:commandButton action="#{navigationBean.buttonToUploadText}" value="Submit"
icon ="ui-icon-arrowstop-1-n" />