我对Web应用程序开发非常陌生。我试图通过JSF命令按钮实现对ManagedBean方法的EJB调用。
这是示例代码: JSF:
<h:commandButton value="CommandButton" action="#{someBean.someBeanMethod}" />
ManagedBean:
@ManagedBean
@ViewScoped
public class SomeBeanClient implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private Service service ;
public String someBeamMethod() throws NamingException {
final Future<String> red = service.someAsyncMethod();
service.someSyncMethod();
return "DummyValue";
}
}
EJB类:
@Stateless
public class Service {
@Asynchronous
public Future<String> someAsyncMethod(){
try {
System.out.println("Gd nyt");
Thread.sleep(10000);
System.out.println("Gd mrning");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return new AsyncResult<String>("success");
}
public void someSyncMethod(){
System.out.println("Gd Day");
}
}
按以下顺序期望S.O.P: Gd nyt 黄金日 GD mrning
实际结果:
servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException: Error calling action method of component with id paneForm:content:PushToGIT:_idJsp72:_idJsp165
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1225)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:775)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:457)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
at ilog.rules.teamserver.web.security.SecurityCheckPointFilter.doFilter(SecurityCheckPointFilter.java:112)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at ilog.rules.teamserver.web.servlets.filter.IlrAccessFilter.doFilter(IlrAccessFilter.java:199)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{someBean.someBeanMethod}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:156)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
... 49 more
Caused by: java.lang.NullPointerException
at com.tiaa.brms.ejb.SomeBeanClient.someBeanMethod(SomeBeanClient.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:76)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:607)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
... 50 more