我的 EL 表达式未在 MyFaces 2.3 和 Spring Boot 2.0.3 应用程序下进行评估

2023-12-10

我有一个 MyFaces 应用程序正在运行Spring Boot 2.0.3, all Servlets and Context Listeners已正确注册和配置,并且显然可以正常工作。就连我的index.jsf页面正在渲染。标签已正确处理.xhtml file.

问题是所有的EL expressions的index.jsf 页面没有被处理/评估。没有抛出错误,但是我放置的位置#{myBean.property}总是被渲染为空String。调试它我发现我的托管 bean 的服务器代码没有被调用。

我尝试更改许多版本的 el-api 和 el-impl 库,但没有人工作。我使用的最终版本是el-api 2.2规格,如下页https://myfaces.apache.org/core23/myfaces-impl/dependency.html

由于没有抛出任何错误,我无法弄清楚问题出在哪里。有人有这个错误吗?是否可以在打包为 jar 文件的 Spring Boot 应用程序下运行 MyFaces 2.3?

以下是我在 Gradle 构建文件上使用的依赖项:

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile("org.jetbrains.kotlin:kotlin-reflect")

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile('org.springframework.boot:spring-boot-starter-test')

    compile 'io.github.microutils:kotlin-logging:1.5.4'

    compile group: 'org.apache.myfaces.core', name: 'myfaces-impl', version: '2.3.1'
    compile group: 'org.apache.myfaces.core', name: 'myfaces-api', version: '2.3.1'
    compile group: 'javax.enterprise', name: 'cdi-api', version: '2.0' //CDI vem embutido no JavaEE 6, mas não no Tomcat 9

    compile group: 'org.glassfish.web', name: 'el-impl', version: '2.2'

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
    compile 'org.springframework.boot:spring-boot-starter-web:2.0.3.RELEASE'
    compile 'org.apache.tomcat.embed:tomcat-embed-jasper:8.5.32'
    compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6'
    compile group: 'org.ocpsoft.rewrite', name: 'rewrite-servlet', version: '3.4.2.Final'

}

以下是加载 Faces servlet 的 Spring 配置:

@Component
open class ConfigureJSF : ServletContextInitializer {
    private val logger = KotlinLogging.logger {}

    @Throws(ServletException::class)
    override fun onStartup(servletContext: ServletContext) {
        //necessary to myfaces be enabled and work in spring boot, once servlets are loaded dynamically.
        servletContext.setInitParameter("org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE", "true")

        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", "true");
        servletContext.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true");

        servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml")
        servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "1")

        servletContext.setInitParameter("org.apache.myfaces.EXPRESSION_FACTORY", "com.sun.el.ExpressionFactoryImpl")
        servletContext.setInitParameter("org.apache.myfaces.CACHE_EL_EXPRESSIONS", "alwaysRecompile")

                    }

    // Register ServletContextListener, necessary for Myfaces.
    @Bean
    open fun listenerRegistrationBean1(): ServletListenerRegistrationBean<ServletContextListener> {
        val bean = ServletListenerRegistrationBean<ServletContextListener>()
        bean.setListener(org.apache.myfaces.webapp.StartupServletContextListener())
        return bean
    }

    @Bean
    fun requestContextListener(): RequestContextListener {
        return RequestContextListener()
    }

    //The faces servlet
    @Bean
    open fun facesServlet(): ServletRegistrationBean<MyFacesServlet> {
        logger.info { "Criando Faces Servlet..." }
        val servlet = org.apache.myfaces.webapp.MyFacesServlet() ;
        val servletRegistrationBean = ServletRegistrationBean(servlet, "*.jsf", "*.xhtml")
        servletRegistrationBean.setLoadOnStartup(1)
//        servletRegistrationBean.order = 1;
        return servletRegistrationBean;
    }

Edit:

我复制了另一个有效项目的依赖配置,出现了相同的结果。所以,问题不在于我粘贴在这里的代码,是的,在于我的环境,我将开始更详细地调查序列。我的有问题的环境包含JDK 8, 9 and 10 and Tomcat 9。我的项目目标是JDK 8。也许这里存在一些不兼容,这就是一些编译注释找不到的原因,我相信我很快就会发现这个问题。


经过几天的努力解决这个问题,改变和组合不同的代码和环境,从JDK 8 to 10, Tomcat 8 and 9,测试在MacOS and Windows 10,来自JSF 2.1实施MyFaces到全新的JSF 2.3实施支持CDI,将最后一个部署在WildFly服务器,我刚刚注意到,在我昂贵的 32 英寸高分辨率显示器上,我的Managed Bean被命名为indexBean使用陌生人角色i上面有小点,这是一本日记ï我不知道它是如何放置或输入在那里的。这就是无论我使用什么配置都找不到我的托管 bean 的原因。

我在 MacOS 上注意到了这个角色。在我的 Windows 上,似乎很难注意到它。我认为这是因为字体差异,而不是硬件。

The strange ï that cost me a week

我很羞愧,但我不会删除这个问题。希望这可以帮助将来的人。编程和生活问题都是这样的:大多数时候错误是在意想不到的地方。

学过的知识。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我的 EL 表达式未在 MyFaces 2.3 和 Spring Boot 2.0.3 应用程序下进行评估 的相关文章

随机推荐