2012-04-27 95 views
3

我的问题是,当我运行一个非常简单的JSF应用程序时,EL标签没有得到渲染。EL标签没有呈现

例如,下面的代码:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html"> 
<h:head> 
    <title>Facelets Hello World</title> 
</h:head> 
<h:body> #{hello.world} </h:body> 
</html> 

显示为#{hello.word}在浏览器中,而不是 “世界,你好!”如应该由我管理的bean返回:

@ManagedBean(name = "hello") 
public class Hello { 
    public String getWorld() { 
     return "Hello World!"; 
    } 
} 

我已经看到了这个问题JSF 2.0 EL tags don't render in browser了,但它并没有帮助我。而且,根据我读到的内容,Tomcat 7声称提供了API和EL 2.2标准的实现。

我使用以下软件/版本:

  • Eclipse的靛蓝3.7.2的Java EE版
  • Eclipse插件:M2E 1.0.2
  • Eclipse插件:M2E-WTP 0.15.2
  • Maven 2的
  • 的Tomcat 7(曾尝试以下的版本)
    • 的Tomcat 7.0 0.10
    • 的Tomcat 7.0.26
    • 的Tomcat 7.0.27
  • MyFaces的2.1.6
  • 的Oracle JDK 1.7.0

如果需要更多信息,我会很乐意提供它。

[EDIT1]

我甚至不知道这是必要的/是正确的,但增加了以下内容web.xml没有解决的问题:

<context-param> 
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name> 
    <param-value>org.apache.el.ExpressionFactoryImpl</param-value> 
</context-param> 

[EDIT2]

的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0"> 
    <display-name>jsf-facelets</display-name> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
    <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>*.html</url-pattern> 
    </servlet-mapping> 
    <context-param> 
     <param-name>javax.faces.DEFAULT_SUFFIX</param-name> 
     <param-value>.xhtml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name> 
     <param-value>org.apache.el.ExpressionFactoryImpl</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
     <param-value>client</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name> 
     <param-value>20</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.PRETTY_HTML</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.AUTO_SCROLL</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.apache.myfaces.SECRET</param-name> 
     <param-value>NzY1NDMyMTA=</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener> 
    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 
</web-app> 
+0

我想您尝试访问你的页面作为的mypage.html的?对?尝试检查它是否适合你mypage.jsf,并更改面临的Servlet *。html的到\t \t \t < servlet-name> Faces Servlet \t \t *。JSF \t也如果JSF2项目可以删除<的context-param> ​​javax.faces.DEFAULT_SUFFIX .xhtml Daniel 2012-04-29 10:11:49

+0

我只是尝试以mypage.html而不是mypage.xhtml的身份访问它,它的工作原理是 – 2012-04-29 10:15:02

+0

奇怪的是,我确信我在很多次之前尝试了这个,但是......谁知道。现在它工作...谢谢你的提示,尝试更改扩展 – 2012-04-29 10:16:22

回答

1

你应该.html等扩展访问你的页面:myPage.html

原因你的servlet映射

<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.html</url-pattern> 
</servlet-mapping> 
+0

如何将URL模式设置为“/faces/*.html”(< - 这不起作用)?即前缀为“/ faces /”路径的所有内容都有.html扩展名 – 2012-04-29 11:32:21

+0

,您知道面孔不是物理文件夹吗?你不需要把你的文件放在faces文件夹中,对吧?如果你设置了/faces/*。html,你不能像这样打开页面/faces/mypage.html? – Daniel 2012-04-29 11:48:10

+0

我意识到这不是一个文件夹,但我想要将一个路径(例如/faces/*.html)映射到JSF,而另一个路径(例如/ rest/*)映射到所有REST调用。我如何告诉JSF:(1)只查看.html文件[AND](2)只查看前缀为/ faces /的URL? – 2012-04-29 11:59:34