Welcome files work by the existence of the file on the file system. If
you are using extension mapped URLs in JSF, your pages have to have
the same extension as the URL to get the welcome file found without a
hack.

So if you want to use *.html in the URL, you have to use *.html as
your view files (which works just fine if you use facelets and not
JSP). Otherwise, you have to make the J2EE spec. happy. This is done
by making blank dummy files. So:

URL: http://someserver/somecontext/somefile.jsf
View: /somefile.xhtml

The servlet specification requires that somefile.jsf exists in order
for somefile to be a welcome page. So, you can simply create an empty
"somefile.jsf" so that the servlet engine can find that file. Once it
finds the file, it does a dispatch to that URL, so the file is never
actually used.

-Andrew




On 10/30/06, Morten Mortensen <[EMAIL PROTECTED]> wrote:

I have a big problem with the "welcome files" as written in the static
web descriptor of a servlet application - and I would also like to know
more about why the URL pattern of the "extensions" filter and the
"faces" servlet can not be e.g. "/*" instead of e.g. "*.jsf".


The context and choises of mine are these:
I want my URL-hieracy as presented in the browser to avoid directly
revealing the technology - and because of this, I do not want URIs to
end in ".jsp", but in ".html". To do this in a regualar, non-JSF
servlet-application, I can map the JSP servlet to e.g. ".html" by
writing -

  <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

- and set the list of "welcome files" to include -

    <welcome-file>
      index.html
    </welcome-file>

This is nothing out of the ordinary; it works well.


But in the context of using JSF in my application, I am completely
unable to set up MyFaces to work with welcomes files in a satisfying
way. If I e.g. have a level in my application addressed in the browser
like http://myhost/something/index.html all is well. However, the
addressing http://myhost/something/ does not work any more; I get an
exception with a root cause -

java.lang.NullPointerException

javax.faces.webapp.UIComponentTag.setupResponseWriter(UIComponentTag.jav
a:929)

javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:310)

org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:70)

org.apache.jsp.index_jsp._jspx_meth_f_view_0(org.apache.jsp.index_jsp:13
0)

org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:103)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va:332)

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

- and I can kind of guess, that the servlet-request needs to be
overridden before the <f:view> tag of my page is processed.


How can I make the "welcome file" adressing operationel? Why is it
impossible to use URL patterns "/*" for the extension filter and the
faces servlet? -Using this URL pattern, servlet-processing ends up in an
infinite recursion and dies when the runtime stack of the processing
thread runs out of space.


My current configuration of MyFaces - where welcome files does not work
- is this:

...
  <!-- MyFaces/JSF: -->
  <!-- extension mapping for adding <script/>, <link/>, and other
resource tags to JSF-pages  -->
  <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <!-- servlet-name must match the name of your
javax.faces.webapp.FacesServlet entry -->
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

  <!-- MyFaces/JSF: -->
  <!-- extension mapping for serving page-independent resources
(javascript, stylesheets, images, etc.)  -->
  <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
  </filter-mapping>

  <!-- MyFaces/JSF: -->
  <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
  </filter-mapping>

  <!-- MyFaces/JSF: -->
  <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>*.html</url-pattern>
<!--
    <url-pattern>/*</url-pattern>
-->
  </filter-mapping>
...
  <servlet-mapping>
    <servlet-name>jsp</servlet-name>  <!-- Specific for Tomcat; other
containers may use e.g. the servlet name "JSP"! -->
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

...

  <!-- MyFaces/JSF: -->
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>

  <!-- MyFaces/JSF: -->
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.html</url-pattern>
<!--
    <url-pattern>/*</url-pattern> ???
-->
  </servlet-mapping>

To make it work, the main pages in the WAR files is named ".jsp", but
are addressed as ".html" in the presented URL (I have no ".jsf" files
and the URL pattern ".jsf" used in the configuration should not come
into play).

Does an explanation for this "I can not use /* as an URL pattern" exist
somewhere?
Does anyone have a small, running example, where "welcome files" using
JSF are operational?

Do I have to encapsulate JSF functionality by using main (JSP) pages in
the form "x.html" (or, say, "x.jsp") and let them include JSF-specific
fragments as "x.jsf"? Isn't this quite clumsy?

I am using MyFaces 1.1.4.

Regards
Morten Sabroe Mortensen


Reply via email to