jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] JSF 2.3 ViewDeclarationLanguage.getViews(...) requires define web config param for JSP VDL (.jsp)

From: Leonardo Uribe <leonardo.uribe_at_irian.at>
Date: Mon, 13 Mar 2017 18:28:48 -0500

Hi

I have been trying to implement some methods for JSF 2.3 and I have found a
small implementation detail that it could be good to define. It is not
exactly a bug
in the spec, it is just something I would like to comment here to have a
clear
understanding, because it looks like something underspecified.

ViewHandler has this method:

    public Stream<java.lang.String> getViews(FacesContext facesContext,
String path,
            int maxDepth, ViewVisitOption... options)

and ViewDeclarationLanguage has this method too:

    public Stream<java.lang.String> getViews(FacesContext facesContext,
String path,
            int maxDepth, ViewVisitOption... options)

In JSF there is only one active ViewHandler, but many VDL instances, always
bound to
an extension.

JspViewDeclarationLanguage --> .jsp
FaceletViewDeclarationLanguage --> .xhtml .view.xml

There are three web config parameters to define this which has as default
values:

javax.faces.DEFAULT_SUFFIX --> .xhtml .view.xml .jsp
javax.faces.FACELETS_SUFFIX --> .xhtml
javax.faces.FACELETS_VIEW_MAPPINGS (and alias facelets.VIEW_MAPPINGS) -->
null

The problem is with the introduction of VDL concept, each VDL is in fact
bound to
an extension. For JSF is .jsp but for Facelets is .xhtml. But this
association was
never specified beyond the previous parameters.

With the introduction of VDL.getViews(...) this becomes more relevant,
because the
developer expect to get an Stream that iterates over views that can handle
the VDL.
Right now, JspViewDeclarationLanguage does not have any check in this part,
so any
resource file is considered a view, which logically is wrong.

Of course, JSP was deprecated and is now considered legacy stuff. But .jsp
has not
been the only extension used for JSF/JSP. There are apps that uses .jspx or
.tiles
The point is there is nothing in the spec to define this, and the binding
between
the VDL and the extension is very important, specially when you see hints
like
ViewVisitOption.RETURN_AS_MINIMAL_IMPLICIT_OUTCOME, which aims to trim the
extensions from the Stream.

The solution is as simple as add a web config parameter like
javax.faces.FACELETS_SUFFIX. In MyFaces I'm adding
org.apache.myfaces.JSP_SUFFIX
but I would like to set javax.faces.JSP_SUFFIX (but to do that we need to
agreed it
here).

In my opinion the web config param is necessary to implement
VDL.getViews(...)
properly, but it can be considered a legacy implementation detail. It is
optional to include the config param in JSF spec.

regards,

Leonardo Uribe