JSF/Bean#{}未呈现/解析 [英] JSF/Bean #{} not rendered/parsed

查看:146
本文介绍了JSF/Bean#{}未呈现/解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF页面内呈现#{}时遇到问题.

i have a problem with rendering #{} inside JSF page.

我正在使用Mojarra 2.1.5和JBoss 7

I'm using Mojarra 2.1.5 and JBoss 7

示例:

JSF页面

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

faces-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?

已更新

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> 

谢谢

推荐答案

根据您更新的问题:

我正在使用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 ...,老实说我不确定我是否需要所有这些内容...在网络应用标签中,我的版本为2.5

JBoss 7已经附带了JSF 2.x实现.您不需要自己提供任何JSF库,请确保没有使用仅会冲突所有内容的旧规范版本.从您的Web应用程序删除这些jsf-*.jar文件.同样,从JSF 2.0开始,Facelets捆绑在JSF库中.也删除 jsf-facelets-*.jar文件.

JBoss 7 already ships with a JSF 2.x implementation. You do not need to supply any JSF library yourself, for sure not of an older spec version which would only conflict everything. Remove those jsf-*.jar files from your webapp. Also, since JSF 2.0, Facelets is bundled in JSF library. Remove the jsf-facelets-*.jar file as well.

JBoss 7是Servlet 3.0兼容的容器.重新声明您的web.xml以符合Servlet 3.0:

JBoss 7 is a Servlet 3.0 compatible container. Redeclare your web.xml to comply 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:

Further you also need to make sure that faces-config.xml complies 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的目标资源/书籍/教程.您可以在我们的JSF标签Wiki页面的底部找到有用的链接.

Please make sure that you aren't reading tutorials targeted on JSF 1.x. JSF 2.x is a major spec change. Make sure that you're reading JSF 2.x targeted resources/books/tutorials. You can find useful links at bottom of our JSF tag wiki page.

这篇关于JSF/Bean#{}未呈现/解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆