我目前正在开发一个使用Java EE的Web项目,最近我决定通过Hibernate-Spring-JSF框架来改进我的编码。但是我遇到了一个问题。当我尝试显示托管bean的内容时,不会打印任何内容。
以下是我的managedBean的代码:
@ManagedBean( name = "moviesBean" )
@SessionScoped
public class MoviesBean implements Serializable {
@Autowired
private transient MoviesService moviesService;
private List<Movies> moviesList;
private Movies movie;
@ManagedProperty( value = "test" )
private String genre;
@PostConstruct
public void init() {
movie = moviesService.getById( 3502914 );
System.out.println( "Id : " + movie.getImdbid() );
}
public List<Movies> getMoviesList() {
return moviesList;
}
public void setMoviesList( List<Movies> moviesList ) {
this.moviesList = moviesList;
}
public Movies getMovie() {
return movie;
}
public void setMovie( Movies movie ) {
this.movie = movie;
}
}
我的jsp的代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Movies detail</title>
</head>
<body>
<f:view>
<h:outputText value="#{moviesBean.genre }"/>
</f:view>
</body>
</html>
所以,正如你所看到的,我只是尝试打印bean MovieesBean的字段'genre'的值,但我得到的只是一个空白页面。难道我做错了什么 ?知道我在服务器端没有任何错误(我使用的是Tomcat 7)。以下是构建路径中的jar:
我几次搜索这个问题,但没有找到任何解决方案。在此先感谢您的帮助!
以下是我的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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>JavaServerFaces</display-name>
<!-- Add Support for Spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
您没有看到类型,因为您的表达不正确。类型是电影的属性。请尝试改为:
<h:outputText value="#{moviesBean.movie.genre}"/>