JSF / Bean#{}未呈现/解析

时间:2012-05-04 18:43:11

标签: jsf jsf-2 el

我在JSF页面中渲染#{}时遇到问题。

我正在使用Mojarra 2.1.5和JBoss 7

示例:

JSF页面

<h:inputText value="#{bean.name}"/>

面-config.xml中

<managed-bean>
   <managed-bean-name>bean</managed-bean-name>
   <managed-bean-class>com.Bean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

HTML输出

#{bean.name}

问题

  1. 为什么我没有看到bean的正确值?
  2. 为什么我得到字符串而不是nothing
  3. 已更新

    web.xml内容:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <!--
    Automatically created by Apache Tomcat JspC.
    -->
    <web-app 
        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-app_3_0.xsd"
        version="3.0">
    
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
    </web-app> 
    

    由于

1 个答案:

答案 0 :(得分:1)

根据您更新的问题:

  

我正在使用Mojarra 2.1.5和JBoss 7

根据您的意见:

  

在我的WEB-INF / lib目录中,我只有:jsf-api-1.2_09,jsf-facelets-1.1.14.jar和jsf-impl-1.2_09.jar ......说实话我不太确定我是否需要所有这些...在web-app标签中我有2.5版本

JBoss 7已经附带了JSF 2.x实现。您不需要自己提供任何JSF库,但肯定不是旧的规范版本,它只会冲突一切。 从您的网络应用中删除这些jsf-*.jar文件。此外,自JSF 2.0以来,Facelets捆绑在JSF库中。 删除 jsf-facelets-*.jar文件。

JBoss 7是一个与Servlet 3.0兼容的容器。重新声明您的web.xml以遵守Servlet 3.0:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    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-app_3_0.xsd"
    version="3.0">

    <!-- Config here. -->

</web-app>

此外,您还需要确保faces-config.xml符合JSF 2.0:

<?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_2_0.xsd"
    version="2.0">

    <!-- Config here. -->

</faces-config>

请确保您没有阅读针对JSF 1.x的教程。 JSF 2.x是一个主要的规范变化。确保您正在阅读JSF 2.x目标资源/书籍/教程。您可以在our JSF tag wiki page底部找到有用的链接。