JSF/Bean #{} not rendered/parsed

≯℡__Kan透↙ 提交于 2019-12-11 18:23:21

问题


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

I'm using Mojarra 2.1.5 and JBoss 7

Example:

JSF Page

<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 Output

#{bean.name}

Question

  1. Why i don't see proper values from bean ?
  2. Why i'm getting string instead of nothing ?

UPDATED

web.xml content:

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

Thanks


回答1:


As per your updated question:

I'm using Mojarra 2.1.5 and JBoss 7

As per your comments:

In my WEB-INF/lib directory i have only: jsf-api-1.2_09, jsf-facelets-1.1.14.jar and jsf-impl-1.2_09.jar... and to be honest i'm not quite sure if i need all of them... In web-app tag i had version 2.5

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

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>

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.



来源:https://stackoverflow.com/questions/10454432/jsf-bean-not-rendered-parsed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!