使用JSF显示消息

问题描述:

我在JSF中是全新的。我正在使用本教程:https://www.tutorialspoint.com/jsf 据此我创建了第一个项目。下面是Java代码:使用JSF显示消息

package com.tutorialspoint.test; 
import javax.faces.bean.ManagedBean; 

@ManagedBean(name = "helloWorld", eager = true) 
public class HelloWorld { 

    public HelloWorld() { 
     System.out.println("HelloWorld started!"); 
    } 

    public String getMessage() { 
     return "Hello World!"; 
    } 

} 

这是home.xhtml文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns = "http://www.w3.org/1999/xhtml"> 
<head> 
    <title>JSF Tutorial!</title> 
</head> 

<body> 
#{helloWorld.getMessage()} 
</body> 
</html> 
当我进入这个地址在我的浏览器

:“JSF教程” http://localhost:8080/helloworld/home.jsf选项卡的标题显示,但内容(文本“你好世界”不是。我可以问你一些提示什么可以丢失? 如果您需要更多的信息/其他文件的代码,请让我知道。 顺便说一句,我是。使用Wildfly 10.1.0,那是我部署更新的.war文件的应用程序服务器 预先感谢

+0

它看起来像缺少代码示例中的一些元素,例如'@ManagedProperty(value =“#{message}”)'看起来很重要。 – Clay

+1

而不是那个教程,我宁愿去完全像这样的2.x集中:https://stackoverflow.com/documentation/jsf/916/getting-started-with-jsf/3036/installing-jsf#t = 201706200625292197528顺便说一句,通过getter这种方式访问​​属性:'#{helloWorld.message}'。但是,你仍然缺乏一些信息。托管的bean是否被创建?你得到面临servlet(javax.faces.webapp.FacesServlet)命中吗?你需要做一些调试工作。 –

+0

如果用''(将名称空间声明添加到)并在浏览器中执行页面的视图源来替换'#helloWorld.message'会怎么样?那么你看到了什么? – Kukeltje

我不知道该表达式语言以外的工作标签 您应该测试此你的身体标记内。

<h:outputText value="#{helloWorld.getMessage()}"/> 

的信息,您可以使用此过:

<h:outputText value="#{helloWorld.message}"/> 
+1

正确配置faces servlet时,表达式语言应该评估外部标签。 –