• Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding the extension of JSF pages in url

 
Debajyoti Kundu
Ranch Hand
Posts: 30
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am working in JSF and web technology after some 3 years, so I've forgot few of the basics :'( . So need some help to brush up. I use eclipse IDE to develope JSF projects.

When I used to create a JSF file, it's extension is basically .jsp and when I ran that file in server .jsf extension used to be displayed in url. But recently, when I did the same thing I got .jsp extension in browser.

In web.xml

when url-pattern is the following, .jsp extension is shown, eg: FileName.jsp
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>



but when I change the url-pattern as per following, .jsf extention is shown , eg: FileName.jsf
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

even if I change the url-pattern to abc or xyz, the webpage url is shown in that format. eg: FileName.abc


So, can you tell me if this is the actual scenario to specify extension of a jsf page, or is this an error.

Thanks in advance for the help





 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jsp" is no longer supported in JSF2. JSF2 is based on Facelets, which use View Templates (.xhtml).

However, here's the way a URL gets processed:

1. When a URL request is presented to the JSF webapp, the URL patterns defined in the WEB-INF/web.xml file are scanned. If there is a match, the corresponding servlet is handed the request. For JSF, the most common URL patterns used are "/faces/*" or "*.jsf", but any valid pattern(s) is/are OK, as long as there's no conflict with other defined patterns.

2. When a URL passes condition #1 and is passed to the FacesServlet, the FacesServlet deconstructs the URL. First it removes the protocol, hostname, port and context, so "https://saloon.javaranch.com/forums/accounts/edit.jsf" would be reduced to "/accounts/edit.jsf" (assuming that the webapp context name was "forums").

3. Then the FacesServlet invokes its Facelets logic to transform the residual URL pattern into a web resource path. In this particular case, "/accounts/edits.jsf" would become "/accounts/edits.xhtml". The actual rules are definable as Servlet Parameters, but this is the default rule. So now, instead of a Uniform Resource Locator, we now have a local resource path. This is the path, relative to the root of the WAR of the "file" that contains the View Template. "file" is in quotes, since a standard WAR is a JAR (ZIP) file, thus the resource isn't literally a file, but that's what you'd get if/when you "explode" (unzip) the WAR, as a lot of webapp servers do.

4. Now that we have a resource path, the Facelets subsystem commences to compile the View Template (hopefully) found at that path location to form a JSF Component Tree (this may be cached for performance reasons). This Component tree is the reference that will be used to locate backing bean resources as the JSF processing lifecycle is followed and is also used to generate the resulting HTML output from the "render response" phase of the JSF lifecycle.

An actual rendering may be more complicated, since Facelets has powerful inclusion and tiling abilities. The URL transformation suffices to locate the root resource. After that, most of the sub-resource references are done as application resources, not URLs, so they will be ".xhtml" not ".jsf".

Finally, the JSF navigation facility is done via URLs rooted at the WAR root, so, for example "/accounts/saveUser.jsf", not ".xhtml". However, general URLs (such as "/okPage.jsp") cannot be specified as navigation targets. Only JSF URLs are permitted.
 
Debajyoti Kundu
Ranch Hand
Posts: 30
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for your input. It is really helpful.

There's one more thing I need to ask - If I use an older version of JSF where JSP is supported, will the page url be rendered as .jsp in browser, if URL patterns specified as "/faces/*
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use an older version of JSF, it won't be supported. And if you're using a JEE webapp server, the built-in JSF won't be version 1.x.

As far as ".jsp" goes, only the oldest JSF implementations actually were JSPs. I think that before JSF 1.0 came out, they'd converted to using "jsp" style pages but were already compiling the "jsp" into a Component Tree. I myself quit using JSP templates when Facelets first came out (they were a third-party add-on for JSF1.x).

I don't use the "/faces/*" URL pattern myself. but I think that a "/faces/abc/def.jsp" URL would convert to resource path "/abc/def.jsp" in a non-Facelets system. You'd have to check the documentation yourself, though, because what I think has no relationship to what actually is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!