You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Todd Patrick <To...@dtn.com> on 2006/05/05 07:14:51 UTC

How do I properly use jsp:forward in MyFaces?

I have a project folder that looks like:
 
/transactionbrowser/
- WEB-INF
- resources
-index.jsp
-tbrowser.jsp
 
 
With the servlet-mapping of:
 
<filter>
    <filter-name>MyFacesExtensionsFilter</filter-name>
 
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-
class>
    <init-param>
        <param-name>maxFileSize</param-name>
        <param-value>20m</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
 
<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>
 
 
The only URLs that work are:
 
http://127.0.0.1:8080/transactionbrowser/faces/tbrowser.jsp
http://127.0.0.1:8080/transactionbrowser/faces/
 
 
On my index.jsp I have:
 
<jsp:forward page="/faces/tbrowser.jsp"/>
 
 
So, when I go to:
 
http://127.0.0.1:8080/transactionbrowser/
 
I see the page, but not with the MyFaces rendering, I still plain
control GUI components with none of the add MyFaces filter files. How do
I use jsp:forward properly to get to:
 
http://127.0.0.1:8080/transactionbrowser/faces/
 
or
 
http://127.0.0.1:8080/transactionbrowser/faces/tbrowser.jsp
 
 
I can't use the following since that doesn't run the MyFaces servlet:
 
<jsp:forward page="/transactionbrowser/faces/tbrowser.jsp"/>
 
 
Thoughts or examples are appreciated.
 
Thanks,
 
--Todd
 
 

RE: How do I properly use jsp:forward in MyFaces?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Todd,

>From your various posts tonight, you seem to have a number of JSF concepts
mixed.  Is this your first Faces Webapp? (That is not meant to be an insult
but a simple question)

If your project folder looks like this as you indicated:

/transactionbrowser/
- WEB-INF
- resources
-index.jsp
-tbrowser.jsp

Then the various mappings you have posted over the past 24 hours have often
been incorrect.  With this webapp, your main url would likely be:
http://127.0.0.1/transactionbrowser and you would expect it to invoke the
welcome page /index.jsp.  Your example index.jsp was listed as:

<jsp:forward page="/faces/tbrowser.jsp"/>

THAT is where your first make came from: your mappings.  JSF is often taught
using SUFFIX mapping so the urls such as /index.jsf are understood to be
imaginary (no such file exists) allowing the servlet to map /index.jsf to
compile the view from the jsp file /index.jsp.  With prefix mapping the url
"/index.jsf" would be equivalent to "/faces/index" see? When you switch to
PREFIX mapping like having mappings start "/faces/whatever", you must skip
the .jsp extension so your index.jsp file should contain:

<jsp:forward page="/faces/tbrowser"/>

Adding the .jsp suffix while using prefix mapping is causing your problem
(that plus how your web.xml Servlet and Filter mappings are setup). I
strongly recommend you to back to the myfaces blank.war and example war
files to see how standard *.jsf suffix mapping works and begin your
application with that style until you are positive you can make a working
JSF application.  It will save you time and effort since searching (the web
or this lists's archives) on the *.jsf SUFFIX extension will result in a
much greater number of relevant posts than if you use PREFIX "/faces/*"
mapping.

Regards,
David Friedman / humble@ix.netcom.com
  -----Original Message-----
  From: Todd Patrick [mailto:Todd.Patrick@dtn.com]
  Sent: Friday, May 05, 2006 1:15 AM
  To: MyFaces Discussion
  Subject: How do I properly use jsp:forward in MyFaces?


  I have a project folder that looks like:

  /transactionbrowser/
  - WEB-INF
  - resources
  -index.jsp
  -tbrowser.jsp


  With the servlet-mapping of:

  <filter>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filte
r-class>
      <init-param>
          <param-name>maxFileSize</param-name>
          <param-value>20m</param-value>
      </init-param>
  </filter>
  <filter-mapping>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>
  <filter-mapping>
      <filter-name>MyFacesExtensionsFilter</filter-name>
      <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
  </filter-mapping>

  <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>


  The only URLs that work are:

  http://127.0.0.1:8080/transactionbrowser/faces/tbrowser.jsp
  http://127.0.0.1:8080/transactionbrowser/faces/


  On my index.jsp I have:

  <jsp:forward page="/faces/tbrowser.jsp"/>


  So, when I go to:

  http://127.0.0.1:8080/transactionbrowser/

  I see the page, but not with the MyFaces rendering, I still plain control
GUI components with none of the add MyFaces filter files. How do I use
jsp:forward properly to get to:

  http://127.0.0.1:8080/transactionbrowser/faces/

  or

  http://127.0.0.1:8080/transactionbrowser/faces/tbrowser.jsp


  I can't use the following since that doesn't run the MyFaces servlet:

  <jsp:forward page="/transactionbrowser/faces/tbrowser.jsp"/>


  Thoughts or examples are appreciated.

  Thanks,

  --Todd