请教各位大虾:
需求:JSP A提交到bean A中经过逻辑判断处理,决定转到BEAN B的JSP B中,该怎样做?环境:RAD 6.0
尝试代码:
MethodBinding method = context.getApplication().createMethodBinding(onloadAction, new Class[0]);
Object result = method.invoke(context, new Object[0]); 
错误报告: 我能保证BeanB已经编译并发布成功。但就是不能初始化。[12/17/07 0:51:34:875 CST] 00000040 SystemOut     O Invoking action: #{BeanB.initialise}
[12/17/07 0:51:34:890 CST] 00000040 jsf           E com.sun.faces.application.ApplicationImpl createAndMaybeStoreManagedBeans Can't instantiate class: 'com.BeanB'.. class com.BeanB : java.lang.InstantiationException
                                 javax.faces.FacesException: Can't instantiate class: 'com.BeanB'.. class com.BeanB : java.lang.InstantiationException
at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:210)
at com.sun.faces.application.ApplicationImpl.createAndMaybeStoreManagedBeans(ApplicationImpl.java:899)
at com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:84)
at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:125)
at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:243)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:156)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:137)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)
at com.navigation.XXNavigationManager.handleNavigation(XXNavigationManager.java)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:90)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:302)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:416)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:201)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:91)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)
Caused by: java.lang.ClassNotFoundException: class com.BeanB : java.lang.InstantiationException
at java.beans.Beans.instantiate(Beans.java:223)
at java.beans.Beans.instantiate(Beans.java:63)
at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:204)
at com.sun.faces.application.ApplicationImpl.createAndMaybeStoreManagedBeans(ApplicationImpl.java:899)
at com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:84)
at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:125)
at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:243)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:156)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:137)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)
at com.navigation.XXNavigationManager.handleNavigation(XXNavigationManager.java)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:90)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:302)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:416)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:201)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:91)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)

解决方案 »

  1.   

    ClassNotFoundException:   class   com.BeanB   ?classpath 路径错了,你那个 BeanB 放错了地方,也许打包到jar里面会更保险些
      

  2.   

    楼主可以用
    BeanB b= (BeanB) SpringFacesUtil.lookupBean("callingList");
    callingList 为face-config.xml里的
    <managed-bean>
            <managed-bean-name>callingList</managed-bean-name>
            <managed-bean-class>com.BeanB</managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    试一试
      

  3.   

    这里面封装相关操作,在一个bean里调用另外一个bean就用getManagedBean(String beanName)就可以了,不用考虑什么初始化的问题
    /**
     * Get servlet context.
     * 
     * @return the servlet context
     */
    public static ServletContext getServletContext() {
    return (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
    }

    /**
     * Get managed bean based on the bean name.
     * 
     * @param beanName the bean name
     * @return the managed bean associated with the bean name
     */
    public static Object getManagedBean(String beanName) {
    Object o = getValueBinding(getJsfEl(beanName)).getValue(FacesContext.getCurrentInstance());

    return o;
    }  

    /**
     * Remove the managed bean based on the bean name.
     * 
     * @param beanName the bean name of the managed bean to be removed
     */
    public static void resetManagedBean(String beanName) {
    getValueBinding(getJsfEl(beanName)).setValue(FacesContext.getCurrentInstance(), null);
    }

    /**
     * Store the managed bean inside the session scope.
     * 
     * @param beanName the name of the managed bean to be stored
     * @param managedBean the managed bean to be stored
     */
    public static void setManagedBeanInSession(String beanName, Object managedBean) {
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(beanName, managedBean);
    }

    /**
     * Get parameter value from request scope.
     * 
     * @param name the name of the parameter
     * @return the parameter value
     */
    public static String getRequestParameter(String name) {
    return (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
    }

    /**
     * Get <code>ApplicationBean</code>.
     * <p>
     * Specific for this application.
     * 
     * @return the application bean
     */
    public static ApplicationBean getApplicationBean() {
    return (ApplicationBean)getManagedBean(BeanNames.APPLICATION_BEAN);


    /**
     * Get <code>SessionBean</code>.
     * <p>
     * Specific for this applicaiton.
     * 
     * @return the session bean
     */
    public static SessionBean getSessionBean() {
    return (SessionBean)getManagedBean(BeanNames.SESSION_BEAN);


    /**
     * Add information message.
     * 
     * @param msg the information message
     */
    public static void addInfoMessage(String msg) {
    addInfoMessage(null, msg);
    }

    /**
     * Add information message to a sepcific client.
     * 
     * @param clientId the client id 
     * @param msg the information message
     */
    public static void addInfoMessage(String clientId, String msg) {
    FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg));
    }

    /**
     * Add error message.
     * 
     * @param msg the error message
     */
    public static void addErrorMessage(String msg) {
    addErrorMessage(null, msg);
    }

    /**
     * Add error message to a sepcific client.
     * 
     * @param clientId the client id 
     * @param msg the error message
     */
    public static void addErrorMessage(String clientId, String msg) {
    FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
    }


    private static Application getApplication() {
    ApplicationFactory appFactory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    return appFactory.getApplication(); 
    }

    private static ValueBinding getValueBinding(String el) {
    return getApplication().createValueBinding(el);
    }

    private static HttpServletRequest getServletRequest() {
    return (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    }

    private static Object getElValue(String el) {
    return getValueBinding(el).getValue(FacesContext.getCurrentInstance());
    }

    private static String getJsfEl(String value) {
    return "#{" + value + "}";
    }
      

  4.   

    补充一下
    SpringFacesUtil是在package com.fm.framework.util包里的
      

  5.   


    //在ABean中
    BBean b= new BBean(p1,
    p2); FacesContext fc = FacesContext.getCurrentInstance();
    Application app = fc.getApplication();
    // 通过createValueBinding().setValue()的方式,直接设定bBean的属性。
    app.createValueBinding("#{sessionScope.bBean}")
    .setValue(fc, b);
                   //返回包含bBean页面
                   return "action";
      

  6.   

    万分感谢各位达人,最后原因在于bean被我定义成abstract了。耽误大家宝贵时间,但你们的建议让我受用非浅。