Custom FaceletFactory in JSF 2.2 / Alternatives for virtual host facelets

。_饼干妹妹 提交于 2019-12-18 08:56:22

问题


Since Mojarra/JSF 2.2. it is not possible anymore to provide a custom FaceletFactory using a web.xml context parameter:

<context-param>
        <param-name>com.sun.faces.faceletFactory</param-name>
        <param-value>my.faces.overrides.MyFaceletFactory</param-value>
</context-param>

My application provides some CMS features, including virtual host support to serve different pages (facelets) based on the currently requested domain. So http://www.domain1.com/index.xhtml returns different content than http://www.otherdomain.com/index.xhtml. The mechanics behind that are not that big of a deal using a custom resource resolver. The real problem when doing that is, that jsf caches the facelets only based on its requested uri, which does not contain the host name ("/index.xhtml" in both cases). I worked around this issue by simply adding the host name to it in my custom FaceletFactory: uri = "/" + getCleanHostName() + "://" + uri;. With JSF 2.2, this does not seem possible anymore. Is there any other way to archive the correct caching behavior in JSF 2.2? Disabling the faces cache is not an option due to its performance impact.


回答1:


There were plans to standardize it in the JSF spec as per issue 611. However, it was cancelled later, because there were abstraction leaks. See also the What's new in JSF 2.2? But the original state was not rolled back anymore in spite of the request of Ed in issue 611 as cited below:

But when I removed the standardized FaceletFactory, in r11053, I didn't put back the context param. Would you be satisfied if I just put it back and it worked as in 2.1?

You may want to create a new issue to wake up this.

The alternative is to replace it it by a custom ResourceHandler (not ResourceResolver, as that's deprecated in JSF 2.2), along with a custom FaceletCacheFactory (standardized since JSF 2.1) which can be registered via <factory><facelet-cache-factory> in faces-config.xml.



来源:https://stackoverflow.com/questions/31984924/custom-faceletfactory-in-jsf-2-2-alternatives-for-virtual-host-facelets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!