facebook

JavaServer Faces page forwarding

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #265323 Reply

    Mark Sanders
    Member

    I hope this is the right topic area for this one…

    MyEclipse 5.1.0 GA Eclipse 3.2.1
    Win XP pro
    Tomcat 5.5.20

    I have gone through the JSFLoginDemo several times. Because I want to get more experiance with JSF, I am currently going through the book JavaServer Faces: The Complete Reference. I’m hoping someone here is familiar with it and/or can help with my issue.

    In Chp 2 – section Application Overwiev, I have built the JSFReg application. The problem I am getting is when I open the url:
    http://localhost/JSFReg/index.faces
    I get the following error

    type Status report

    message /faces/main.jsp

    description The requested resource (/faces/main.jsp) is not available.

    the code for the index.jsp page is simply this:

    ______________________________________________________
    <%@ page language=”java” pageEncoding=”ISO-8859-1″%>
    <%@ taglib uri=”http://java.sun.com/jsf/html&#8221; prefix=”h” %>
    <%@ taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f” %>

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
    %>

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head>
    <base href=”<%=basePath%>”>

    <title>A Simple JavaServer Faces Registration Application</title>

    <meta http-equiv=”pragma” content=”no-cache”>
    <meta http-equiv=”cache-control” content=”no-cache”>
    <meta http-equiv=”expires” content=”0″>
    <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
    <meta http-equiv=”description” content=”This is my page”>
    <!–
    <link rel=”stylesheet” type=”text/css” href=”styles.css”>
    –>

    </head>

    <body>
    <f:view>
    <jsp:forward page=”/faces/main.jsp”></jsp:forward> <br>
    </f:view>
    </body>
    </html>
    ______________________________________________

    here is my faces-config.xml file:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE faces-config PUBLIC “-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN” “http://java.sun.com/dtd/web-facesconfig_1_1.dtd”&gt;

    <faces-config >
    <navigation-rule>
    <from-view-id>/index.jsp</from-view-id>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/main.jsp</from-view-id>
    <navigation-case>
    <from-action>register</from-action>
    <to-view-id>/register.jsp</to-view-id>
    </navigation-case></navigation-rule>
    <navigation-rule>
    <from-view-id>/register.jsp</from-view-id>
    <navigation-case>
    <from-action>register</from-action>
    <to-view-id>/confirm.jsp</to-view-id>
    </navigation-case></navigation-rule>

    <managed-bean>
    <managed-bean-name>UserBean</managed-bean-name>
    <managed-bean-class>
    com.jsfreg.bean.UserBean
    </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>

    <managed-property>
    <property-name>firstName</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    <managed-property>
    <property-name>lastName</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    <managed-property>
    <property-name>gender</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    <managed-property>
    <property-name>email</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    <managed-property>
    <property-name>serviceLevel</property-name>
    <property-class>java.lang.String</property-class>
    <value></value>
    </managed-property>
    </managed-bean>

    <navigation-rule>
    <from-view-id>/confirm.jsp</from-view-id>
    <navigation-case>
    <from-action>revise</from-action>
    <to-view-id>/register.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/done.jsp</to-view-id>
    </navigation-case></navigation-rule>
    <navigation-rule>
    <from-view-id>/done.jsp</from-view-id>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/main.jsp</from-view-id>
    </navigation-rule></faces-config>

    _______________________________________________
    I have verified that all my libs were in the project and deployed. Let me know if you would like to see any more information.

    By the way, if you have access to books 24×7, the above mentioned book is available on the site.

    Thanks

    #265420 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

    My guess is that in your web.xml file, you mapped FacesServlet to /faces/* but you are trying to use the .faces extension to access your pages instead.

    #265443 Reply

    Mark Sanders
    Member

    As a newbi I need you to help explain it to me. this is my web.xml file for the above mentioned project. it looks the same to me as the one from the JSFLoginDemo example from MyEclipse help/tutorial.

    —————————————-
    <?xml version=”1.0″ encoding=”UTF-8″?>
    <web-app xmlns=”http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; version=”2.4″ xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”&gt;
    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    </web-app>

    ——————————————————

    Maybe I am not including enough info or am missing something. Let me add more info.

    the project says i should open the webpage at http://localhost/JSFReg/
    i have been trying http://localhost/JSFReg/index.faces because if i use the other url i get this error.

    —————————————–

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Cannot find FacesContext
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    root cause

    javax.servlet.ServletException: Cannot find FacesContext
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    root cause

    javax.servlet.jsp.JspException: Cannot find FacesContext
    javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:399)
    com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
    org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java:109)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:84)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    ————————————————
    hope this is useful in supporting this.

    thanks

    #265458 Reply

    Mark Sanders
    Member

    here is an update. i down loaded the source code which has not helped much, but i did find that he also used an index.html file that he forgets to mention in the book. this way http://localhost/JSFReg2/ actually does something. it displays a page with a link that is supposed to take me to the index.jsp page which forwads to the main.jsp page. i end up with the original problem:

    description The requested resource (/faces/main.jsp) is not available.

    so i bypassed the index.jsp. i am not sure why he was forwarding in the first place.

    —————————————–
    index.html

    <body>
    <h1>
    Chapter 2 Example Application
    </h1>

    <ul>
    <li>
    <p>
    <a href=”main.faces”>JSFReg – A first JSF example application,
    Pages 15-34</a>
    </p>
    </li>
    </ul>

    <hr>
    </body>
    ——————————————————–

    i obviously have something else going on because now i have another issue. when i click on the link in main.jsp it goes nowhere. – dead link ???

    ———————————————————
    main.jsp

    body>
    <f:view>
    <h:form>
    <h2>
    JSF Registration App
    </h2>
    <h:commandLink action=”register1″>
    <h:outputText value=”Click here to register..”/>
    </h:commandLink>
    </h:form> <br>
    </f:view>
    </body>
    ———————————————————
    i tried adding immidiat=”true” and then id=”click” but nothing is working.

    when i set this up the first time i used JSTL 1.1 and the second time 1.0 no difference.

    I would like to think i did something stupid or missed something. i have spent a lot of time going over my code vs his and can’t find any differences.

    getting a little bummed and frustrated now.

    😥

    #265464 Reply

    Riyad Kalla
    Member

    I think you are getting buried in miniscule detail here… you have to first and foremost realize this:
    Whatever you map the FacesServlet to (*.faces in this case) you have to use to access your JSP pages. How JSF works, is when you use a URL with your pattern in it (/mypage.faces for example) it triggers FacesServlet. What it does then is setup the FacesContext and a bunch of stuff on the server side, THEN it looks for a JSP page with exactly the same name with a “.jsp” extension in the same path, like /mypage.jsp and forwards the user to it automatically.

    So if you have a page main.jsp, you access it with main.faces. If you have a page under /order/user/signup.jsp you access it with /order/user/signup.faces

    If you have a link in some page that goes to /travel/cruise/book.faces you better have a /travel/cruise/book.jsp file somewhere in your project, because that is what FacesServlet is going to look for.

    So with that in mind, take a slow look back at your application. Simplify things, start with 1 page. Then add a second and a 3rd with that fact always in your head.

    #265474 Reply

    Mark Sanders
    Member

    okay – i’ll try, but what seems to throw me off is that (using the JSFLoginDemo as an example) i create my jsp pages from my faces-config.xml. then in my jsp pages i am creating an action=”…, then i go to faces-config.xml and create the link between the two pages using the same action term.

    So to me, the actual code in the jsp is not calling x.jsp or x.faces. it is sending an action and the faces-config-xml making the move. now when i create a connection i only have the options for action or outcome. the file i’m linking to is greyed out and is a .jsp. the xml file looks right.

    that was just an FYI or IMO. you don’t need to respond to that. i’m going to go back through everthing again – one step at a time.

    thanks

    #265667 Reply

    Mark Sanders
    Member

    Thanks, you were right. i had a couple of other coding issues i fixed and all seems well.

    #265669 Reply

    Riyad Kalla
    Member

    Glad it’s working now, sometimes the smallest thing throws a monkey wrench into the entire app.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: JavaServer Faces page forwarding

You must be logged in to post in the forum log in