This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Why do I need a forward page to the JSF index page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Why do I need a forward page to the JSF index page?" Watch "Why do I need a forward page to the JSF index page?" New topic
Author

Why do I need a forward page to the JSF index page?

Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
I have read a few chapters from the first edition but have not bought the new edition yet as I not have time to read it yet. But I have been waiting for it as it describes the new and current JSF syntax. And I also hope that the code examples are easier to get up and running if they are written for the new libraries available on the net.

Anyway, here is a little question I feel not understand fully yet ... Why do I have to have a page that forwards so the first page (index page, main page) for the JSF application? What architectural thing prevents me from have the index page for the JSF application configured as the welcome page for the web application? Provided that the Faces servlet is configured to handle that page of course.


Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Not sure, But I guess this was common as there was an old bug in Tomcat that didn't accept a servlet in the welcome files list, however starting from tomcat 5 this issue is fixed. See this old thread Servlet-welcome-file-list
Ed Burns
author
Ranch Hand

Joined: Sep 11, 2006
Posts: 82
    
    5
Hany Shafik is probably right. In fact, you don't need it. Just make sure that in your <welcome-file-list> you include the proper mapping for the faces servlet. For example,

<welcome-file-list>
<welcome-file>faces/register.xhtml</welcome-file>
</welcome-file-list>

for servlets using /faces/* as the mapping.

This approach also works for error pages.

Ed
Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
Hum, it actually worked! I am sure I have tried something like that before without getting it to work but I must have made something wrong. And I like it better this way without more pages than necessary.

Thanks! And I'll promise I will buy your book about JSF 2.0 soon! I learnt a lot from the first edition and have been waiting for this new edition. I particularly appreciated that you explained that much about the framework behind the scenes.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Hi,

I will go with Ed Burns,

depends upon our requirement, we can use or avoid index.jsp.
but the question is "Why do I need a forward page to the JSF index page?"
if you are using index.jsp for sure in your application, then definitely you need forward page as to stop our application entering into the JSF life cycle before displaying the initial page of the application.

Sun Certified Java Programmer with 93 percent
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

For the most part, any page request made directly by the container doesn't work well with a servlet-dispatched framework such as JSF or Struts. This is especially true of the login JSPs, but error JSPs and other pages of the same sort also have problems. The reason appears to be that the container is invoking the page directly instead of via the normal network channel and not all the necessary context is available. Login pages also have the problem that they're injected as a shunt to a normal page request, so not only does the login page have to be invoked, but the original page request has to be preserved, since once login succeeds, control is re-routed back to where the need for login was detected.


Customer surveys are for companies who didn't pay proper attention to begin with.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

This sounds much like a bug or maybe a missing piece in the specification to me. Is this specific to a Servlet container or Servlet API or is it a known problem for all well-known containers?

Marco
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Marco Ehrentreich wrote:This sounds much like a bug or maybe a missing piece in the specification to me. Is this specific to a Servlet container or Servlet API or is it a known problem for all well-known containers?

Marco


As far as I'm aware, it's not so much a bug as an acknowledgement that pages presented on behalf of the appserver itself don't get the full resource set that pages requested via http(s) to the application would. In the case of login pages, that's as much for security reasons as anything else, but I can think of several other reasons why this would be desirable behaviour.

I've been digging around in the Sun official docs, and most of the formal specs seem mute on the whole area, but that's given me an excuse to get an updated set of docs.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why do I need a forward page to the JSF index page?
 
Similar Threads
jsessionid always appended to urls on first request
PortletException
how to disable the ability that last accessed page is remembered
ANNOUNCE: Speed up your Data-Driven JSF/Seam Application by Two Orders of Magnitude - Part 2
JSF 2.0 vs 1.x