日期:2014-05-17  浏览次数:20774 次

高分求答:JSF中不能取得bean
web.xml中有如下配置
XML code

<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>
        ......
        /WEB-INF/faces-managed-beans-user.xml,
                ... ...
    </param-value>
</context-param>



faces-managed-beans-user.xml中有 bean的配置(alertConfigBean和ruleBean)如下:
XML code

<managed-bean>
     <managed-bean-name>alertConfigBean</managed-bean-name>
     <managed-bean-class>
           com.test.bean.rule.AlertConfigBean
     </managed-bean-class>
     <managed-bean-scope>application</managed-bean-scope>
</managed-bean>
......
    <managed-bean>
        <managed-bean-name>ruleBean</managed-bean-name>
        <managed-bean-class>
            com.infosec.secsrv.scms20.bean.rule.RuleBean
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>



我想在RuleBean中取得alertConfigBean,怎么获取?
用下面的代码不可以吗?为什么取出来的是null?
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("alertConfigBean");
求高手解答!

------解决方案--------------------
国庆国庆,全国同庆!放下代码,去玩吧!
------解决方案--------------------
探讨
我想在RuleBean中取得alertConfigBean,怎么获取?
用下面的代码不可以吗?为什么取出来的是null?
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("alertConfigBean");

------解决方案--------------------
探讨
引用:
我想在RuleBean中取得alertConfigBean,怎么获取?
用下面的代码不可以吗?为什么取出来的是null?
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("alertConfigBean");

你直接import,然后引用不好……

------解决方案--------------------
遇到同样类似问题啊...
------解决方案--------------------
在定义ruleBean时把alertConfigBean写在<property>里不行吗
------解决方案--------------------
你把FacesContext.getCurrentInstance().getExternalContext().getApplicationMap()打印一下
应该是没有给alertConfigBean实例化,当然就是空的了
------解决方案--------------------
JSF,向楼主学习一下
------解决方案--------------------

------解决方案--------------------
http://www.360doc.com/content/11/0118/13/19525_87338785.shtml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>modelBean</managed-bean-name>
<managed-bean-class>myproject.ModelBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>backingBean</managed-bean-name>
<managed-bean-class>myproject.BackingBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>