从其他项目中引用manage bean

时间:2017-04-28 12:28:31

标签: eclipse google-app-engine jsf

我使用的是Google App Engine 1.9.51。在Eclipse中,我为多服务创建了4个项目: - 一只耳朵(GoalsCompletion) - 一个常见的jave项目(GoalsCompletion_common) - 2个Web应用程序(GoalsCompletion_default和GoalsComletion_task),如下面的屏幕截图所示。

enter image description here

在网络应用中(例如GoalsCompletion_default), - 我有几个jsf文件引用公共项目中定义的manage bean(即.GoalsCompletion_common)。 - 我也有jave文件引用普通项目中定义的接口。

我将公共项目作为Web应用程序部署的依赖项包括在内,如下所示:

enter image description here

我面临的问题是在网络应用程序中,当我在通用项目中调用管理bean的getter时,没有任何回报。

例如

web.xml中的

<context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>#{userSession.theme}</param-value>

在jsf页面

Current Theme: #{userSession.theme}

如果我将UserSession Manage bean从公共项目移动到Web应用程序,则返回值。

GAE并没有抱怨没有找到类,没有错误只返回空值,所以我的配置部署似乎有些不对劲。有什么帮助吗?

2 个答案:

答案 0 :(得分:0)

几次尝试和错误......

实际上在Web应用程序项目中,如果包含公共项目作为其Web部署程序集的依赖项,我将不需要在公共项目/ WEB-INF文件夹中使用faces-config.xml。

在这种情况下,我可以使用注释而不是xml来配置bean。

这个提及不早期工作的原因是因为每当我对常见项目的pom.xml进行更改(例如包含新的依赖项或更改依赖项版本)时,Eclipse将删除我的设置Web Deployment Assembly 。

因此,我需要确保在部署/运行服务器之前,其他Web项目的Web部署程序部分中存在公共项目。如果没有,我需要再加入。

不确定这是一种设置永久性的方法

答案 1 :(得分:-1)

感谢OTM对上述帖子的建议......

Ya,一个简单的解决方案就是在faces-config.xml中定义托管bean,并在普通项目中放置在\ META-INF下。

faces-config.xml示例:

<?xml version="1.0"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

    <managed-bean>
        <managed-bean-name>beanName</managed-bean-name>
        <managed-bean-class>package.BeanName</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>