5 Replies - 1461 Views - Last Post: 14 March 2012 - 05:31 PM

#1 Andreika_86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 20-November 11

JSF returns blank page

Posted 13 March 2012 - 02:08 PM

Hello everyone!
I am developing a web application, and I am going to use some jsf in it. Since I am not fammiliar with it I decided to write simple Hell World application for the beginning. The problem is it returns a blank page, it shows the name of a page on the tab of a browser - but it does not show Hello World message! What is weird - before that I was getting different errors and exeptions - but now just blank page! I searched for some solutions and they did not apply to me, really dond know what it might be... Any help greatly appriciated!!!

web.xml
<?xml version='1.0' encoding='UTF-8'?>   
<web-app version="2.5" 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_2_5.xsd">   
     <display-name>JSF Made Easy</display-name>   
       <servlet id="JSF_Front_Controller_Servlet">   
         <servlet-name>Faces Servlet</servlet-name>   
           <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>   
         </servlet> 
  
     <servlet-mapping>   
        <servlet-name>Faces Servlet</servlet-name>   
        <url-pattern>*.faces</url-pattern>   
     </servlet-mapping>   
</web-app>  



faces-config.xml
<?xml version="1.0"?>  
<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">  
</faces-config>



hello.jsp (or xhtml - tried both)
    <!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"  
          xmlns:h="http://java.sun.com/jsf/html"  
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets">  
        
        <h:head>  
            <title>Simple JSF Page - xhtml</title>  
        </h:head>  
          
        <body>  
        <h:outputText value="Hello World!"/>
	  
   
        </body>  
      
    </html>  


This post has been edited by Andreika_86: 13 March 2012 - 02:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: JSF returns blank page

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: JSF returns blank page

Posted 13 March 2012 - 04:00 PM

Try this.

  • Put a servlet mapping from JSF to the Faces Servlet. I'm using Servlet 3.0. You may need to change the 3.0's to 2.5's wherever they occur in this file if your using Servlet 2.5.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="3.0"
     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">
     <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>/faces/*</url-pattern>
     </servlet-mapping>
     <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
     </servlet-mapping>
     <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.htm</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>default.html</welcome-file>
      <welcome-file>default.htm</welcome-file>
      <welcome-file>default.jsp</welcome-file>
     </welcome-file-list>
    </web-app>
    
    


  • Create a redirect from index.jsp to hello.jsf. Create index.jsp with the following code:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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>Insert title here</title>
    </head>
    <body>
    <jsp:forward page="hello.jsf"></jsp:forward>
    </body>
    </html>
    
    


  • Create hello.xhtml with the following code:

    <!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"
    	xmlns:h="http://java.sun.com/jsf/html">
    <h:body>
    	<h:outputText value="Hello World" />
    </h:body>
    </html>
    
    

Was This Post Helpful? 1
  • +
  • -

#3 Andreika_86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 20-November 11

Re: JSF returns blank page

Posted 13 March 2012 - 05:22 PM

I tried exacly what you recommended, although I changed <jsp:forward page="hello.jsf"> to hello.xhtml - because I was getting an error. The result is the same - no errors, no exeptions - just blank page...
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: JSF returns blank page

Posted 13 March 2012 - 08:50 PM

Hmm... you shouldn't have had to change it to hello.xhtml. I don't know. Did you put Mojarra (or MyFaces) on the the classpath? They're the JSF reference implementations. If you're using Netbeans that might have been done for you when you created a JSF project. In Eclipse you have to go through a wizard and download the implementation. If you're not using an IDE, you would have had to download it yourself. Does your IDE complain about not recognizing tag libraries?

If you're using Netbeans, here's a tutorial that looks good. It looks as if Mojarra is installed automatically. If you're not using Netbeans I suggest doing so, because it looks pretty darn easy to setup -- much easier than in Eclipse.

This post has been edited by blackcompe: 13 March 2012 - 08:52 PM

Was This Post Helpful? 0
  • +
  • -

#5 Andreika_86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 20-November 11

Re: JSF returns blank page

Posted 14 March 2012 - 03:16 PM

It started working eventually, after restarting a computer! Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: JSF returns blank page

Posted 14 March 2012 - 05:31 PM

Cool. You probably just needed to restart your server.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1