[英]Configuration of com.sun.faces.config.ConfigureListener
I'm reviewing a current JSF project where the web.xml
configuration contains:我正在审查当前的 JSF 项目,其中
web.xml
配置包含:
*.xhtml
) *.xhtml
上配置)com.sun.faces.config.ConfigureListener
com.sun.faces.config.ConfigureListener
I'm using JSF 2.2 and Mojarra implementation.我正在使用 JSF 2.2 和 Mojarra 实现。
I'm confused about the ConfigureListener
.我对
ConfigureListener
感到困惑。 Is this class needed in the configuration?配置中需要这个类吗? What is the goal of this class?
这门课的目标是什么? I couldn't find any information and the class has almost no javadoc.
我找不到任何信息,而且该课程几乎没有 javadoc。
If I remove this configuration, everything seem to work the same way.如果我删除此配置,一切似乎都以相同的方式工作。 Thus I guess that the
ConfigureListener
could or should be removed but I am not sure.因此,我猜想可以或应该删除
ConfigureListener
,但我不确定。
The ConfigureListener
is normally automatically registered via /META-INF/jsf_core.tld
file of Mojarra implementation JAR file. ConfigureListener
通常通过 Mojarra 实现 JAR 文件的/META-INF/jsf_core.tld
文件自动注册。 Additionally, the ConfigureListener
is explicitly registered via a Servlet 3.0 ServletContainerInitializer
in order to workaround an old GlassFish v3 bug (note: v3, not 3.0.x, thus really that one first GF3 version ever).此外,
ConfigureListener
通过 Servlet 3.0 ServletContainerInitializer
显式注册,以解决旧的 GlassFish v3 错误(注意:v3,而不是 3.0.x,因此是有史以来第一个 GF3 版本)。
There exist situations wherein the auto-registration via .tld
file is insufficient.存在通过
.tld
文件自动注册不足的情况。 The well known one is when the webapp is deployed to Jetty .众所周知,当 webapp 部署到Jetty 时。 This is explained in detail in this Q&A: could not find Factory: javax.faces.context.FacesContextFactory .
这在这个问答中有详细解释: 找不到工厂:javax.faces.context.FacesContextFactory 。
Also, as mentioned before and in that detailed answer, GlassFish v3 has a bug wherein the TLD file is scanned too late and thus JSF couldn't do its necessary initialization thing at the right moment.此外,正如之前和那个详细答案中提到的,GlassFish v3 有一个错误,其中 TLD 文件被扫描得太晚,因此 JSF 无法在正确的时间执行其必要的初始化操作。 You'd then need to explicitly register the
ConfigureListener
in webapp's web.xml
.然后,您需要在 webapp 的
web.xml
显式注册ConfigureListener
。
But if it works for you when it's not explicitly registered in web.xml
, then just keep it out.但是如果它没有在
web.xml
显式注册时对你web.xml
,那么就把它放在外面。 Less noise in web.xml
is better. web.xml
噪音越小越好。 But if you happen to possibly deploy to a container sensitive to the mentioned problem (so when your webapp is actually a publicly distributed one and you have no control over choice of target container), then you'd better keep it in "for the case that".但是,如果您碰巧可能部署到对上述问题敏感的容器(因此,当您的 web 应用程序实际上是一个公开分发的应用程序并且您无法控制目标容器的选择时),那么您最好将其保留在“对于这种情况”那”。
Update : It appears that Tomcat 8.x shows buggy behavior when this entry is enabled in web.xml
: this listener will actually be executed twice instead of only once.更新:在
web.xml
启用此条目时,Tomcat 8.x 似乎显示错误行为:此侦听器实际上将执行两次而不是仅执行一次。 The consequence is disastrous: among others, all JSF event listeners will be registered twice and component libraries will be loaded twice.结果是灾难性的:除其他外,所有 JSF 事件侦听器都将被注册两次,组件库将被加载两次。 This leads only to conflicts during runtime.
这只会在运行时导致冲突。 In other words, when deploying to Tomcat, make sure that this entry is removed from
web.xml
.换句话说,在部署到 Tomcat 时,请确保从
web.xml
删除此条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.