[英]What is the use of faces-config.xml in JSF 2?
在JSF 2对注释的大力支持之后,我想知道我将使用faces-config.xml
。 它现在的重要性是什么?
换句话说,只能通过faces-config.xml
而不是通过注释来完成哪些配置?
现在我用它的所有东西都是声明Spring的EL解析器。
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
它仍然被用于许多无法注释的东西。 例如自定义JSF验证消息:
<application>
<message-bundle>com.example.i18n.messages</message-bundle>
</application>
一个全局的i18n包(这样你就不需要在每个视图中声明<f:loadBundle>
):
<application>
<resource-bundle>
<base-name>com.example.i18n.Text</base-name>
<var>text</var>
</resource-bundle>
</application>
明确支持i18n语言环境(这样即使有消息包或资源包,也会忽略未声明的语句):
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>nl</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>de</supported-locale>
</locale-config>
</application>
自定义视图处理程序 :
<application>
<view-handler>com.example.SomeViewHandler</view-handler>
</application>
阶段监听器 (仍然没有注释):
<lifecycle>
<phase-listener>com.example.SomePhaseListener</phase-listener>
</lifecycle>
无法注释的托管bean(下面给出#{now}
上的当前Date
):
<managed-bean>
<description>Current date and time</description>
<managed-bean-name>now</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
自定义工厂,例如自定义异常处理程序工厂(它还允许工厂使用FacesContext
, ExternalContext
, LifeCycle
等等,以便您可以提供自定义实现):
<factory>
<exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
</factory>
仅列出常用的名称。 如果IDE中有faces-config.xml
标记自动完成,则可以全部找到它们。 由于新的注释和隐式导航,不再需要托管bean,验证器,转换器,组件,渲染器和点对点导航案例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.