Custom FaceletFactory in JSF 2.2 / Alternatives for Virtual Hosts

Since Mojarra / JSF 2.2. it is now impossible to create a custom FaceletFactory using the 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, for serving different pages (facelets) based on the requested domain. Therefore, http://www.domain1.com/index.xhtml returns a different content than http://www.otherdomain.com/index.xhtml . The mechanics behind this are not so important using a dedicated resource editor. The real problem with this is that jsf caches chips only based on the requested uri that does not contain the host name ( "/index.xhtml" in both cases). I worked on this problem by simply adding the hostname to my custom FaceletFactory : uri = "/" + getCleanHostName() + "://" + uri; . With JSF 2.2, this no longer seems possible. Is there any other way to archive the correct caching behavior in JSF 2.2? Disabling the face cache is not an option due to its impact on performance.

+3
source share
1 answer

There were plans for standardization in the JSF specification for issue 611 . However, this was canceled later because there were leaks of abstraction. See Also What's New in JSF 2.2? But the initial state no longer rolled back despite an Ed request in release 611, as follows

But when I deleted the standardized FaceletFactory, in r11053 I did not return the context parameter. Will you be satisfied if I just return it and it worked as in 2.1?

You might want to create a new problem to wake this up.

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

+3
source

Source: https://habr.com/ru/post/1245405/


All Articles