0

I am currently working on a web project with Java EE and I recently decided to improve my coding thanks to frameworks Hibernate-Spring-JSF. However I encountered a problem. When I try to display the content of a managed bean, nothing is printed.

Here is the code of my 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;
    }
}

And the code of my 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>

So, as you can see I just try to print the value of the field 'genre' of the bean MovieesBean, but all I have in return is a blank page. Am I doing something wrong ? Knowing that I have not any errors on the server side (I am using Tomcat 7). Here are the jars in the build path :

Build path libs

I googled this problem several times but didn't find any solution. Thanks in advance for your help !

Here is the code of my web.xml file :

<?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>
Jean DELI
  • 38
  • 1
  • 7
  • 1
    First of all, Spring and Hibernate are NOT Java EE, CDI and JPA(2) are. So please go for the latter. And seeing that you use JSF2.2, I'd drop using the tutorial you found since JSP is deprecated since JSF2.0 (7 years ago) and go for facelets. http://stackoverflow.com/questions/13092161/why-facelets-is-preferred-over-jsp-as-the-view-definition-language-from-jsf2-0-o – Kukeltje Feb 15 '16 at 19:59
  • Rightclick page in browser, *View Source*. What do you see? Do you still see unparsed JSF tags in there or its generated HTML output? Nonetheless, Kukeltje is 100% right. You started wrong while learning JSF. JSP is **deprecated** since 2009 and succeeded by Facelets as view technology for JSF. And true Java EE offers CDI and JPA out the box without the need to install 3rd party libraries to achieve the same (Spring and Hibernate). – BalusC Feb 15 '16 at 23:05

1 Answers1

0

You are not seeing genre because your expression is incorrect. Genre is Movies's attribute. Try instead:

<h:outputText value="#{moviesBean.movie.genre}"/>