关于jsf 2:在JSF 2中,faces-config.xml的用途是什么?

What is the use of faces-config.xml in JSF 2?

在JSF 2对注释的大力支持之后,我想知道将faces-config.xml用于什么。现在它的重要性是什么?

换句话说,只能通过faces-config.xml而不通过注释完成的配置是什么?

现在我所使用的只是声明Spring的EL解析器。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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">

   
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>
</faces-config>


它仍然可以用于许多无法注释的内容。例如。定制JSF验证消息:

1
2
    <message-bundle>com.example.i18n.messages</message-bundle>
</application>

全局i18n捆绑包(这样就不必在每个视图中声明<f:loadBundle>):

1
2
3
4
5
    <resource-bundle>
        <base-name>com.example.i18n.Text</base-name>
        <var>text</var>
    </resource-bundle>
</application>

明确支持的i18n语言环境(即使存在消息捆绑包或资源捆绑包,也将忽略未声明的语言环境):

1
2
3
4
5
6
7
    <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>

自定义视图处理程序:

1
2
    <view-handler>com.example.SomeViewHandler</view-handler>
</application>

阶段监听器(仍然没有注释):

1
2
3
<lifecycle>
    <phase-listener>com.example.SomePhaseListener</phase-listener>
</lifecycle>

无法注释的托管bean(以下一个给出了#{now}上的当前Date):

1
2
3
4
5
6
<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>

自定义工厂,例如自定义异常处理程序工厂(它还允许FacesContextExternalContextLifeCycle等工厂,以便您可以提供自定义实现):

1
2
3
<factory>
    <exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
</factory>

仅列出常用名称。如果您的IDE中具有faces-config.xml标记自动完成功能,则可以全部找到它们。由于有了新的注释和隐式导航,因此不再需要托管的Bean,验证器,转换器,组件,渲染器和点对点导航用例。