91

在 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>
4

1 回答 1

143

它仍然可以用于许多无法注释的事情。例如自定义 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(下面给出了 current Dateon #{now}):

<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>

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

<factory>
    <exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
</factory>

只列举常用的。如果您faces-config.xml的 IDE 中有标签自动完成功能,您可以将它们全部找出来。由于新的注释和隐式导航,不再需要托管 bean、验证器、转换器、组件、渲染器和点对点导航案例。

于 2011-09-28T13:01:08.023 回答