1

Using JSF 1.2 with Facelets 1.x on top of IBM portal server 6.1

We are making extensive use of the templating, composition, decorate and include mechanisms that facelets provide which is absolutely fantastic and allows us to modularise our html extensively.

One "feature" we do not like is if we make a mistake in our filenames or pathnames when referring to them in an include or a src attribute, the page does not render at all, just a completey blank screen with nothing written to any log and no exceptions thrown. This can hamper debugging quite a bit.

The particular case that prompted this question was one where we promoted our app from our local windows machines to our unix staging test machine. One of our included fragments contained a lowercase s instead of an uppercase S in the name and it took the developer assigned to fix it quite a long time to track it down.

Is there any way we can get facelets to log or throw exception when it cannot find an html fragment ?

4

1 に答える 1

2

JSF 2.x throws a FileNotFoundException on that. I don't have a Facelets 1.x playground environment right now, so I can't test it for you, but theoretically you should be able to catch it by implementing a custom Facelets resource resolver by DefaultResourceResolver which checks for a null outcome in the resolveUrl() method.

Something like this:

import com.sun.facelets.impl.DefaultResourceResolver;

public class CustomResourceResolver extends DefaultResourceResolver {

    @Override
    public URL resolveUrl(String resource) {
        URL url = super.resolveUrl(resource);

        if (url == null) {
            throw new FacesException(new FileNotFoundException(resource));
            // Perhaps add a logging statement instead if this exception
            // is after all actually completely swallowed for some reason.
        }

        return url;
    }

}

To get it to run, register it as follows in web.xml:

<context-param>
    <param-name>facelets.RESOURCE_RESOLVER</param-name>
    <param-value>com.example.CustomResourceResolver</param-value>
</context-param>
于 2012-06-21T13:24:15.227 に答える