在JSF 2中使用faces-config.xml有什么用?

Mah*_*leh 87 jsf faces-config 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>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 139

它仍然被用于许多无法注释的东西.例如自定义JSF验证消息:

<application>
    <message-bundle>com.example.i18n.messages</message-bundle>
</application>
Run Code Online (Sandbox Code Playgroud)

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

<application>
    <resource-bundle>
        <base-name>com.example.i18n.Text</base-name>
        <var>text</var>
    </resource-bundle>
</application>
Run Code Online (Sandbox Code Playgroud)

明确支持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>
Run Code Online (Sandbox Code Playgroud)

自定义视图处理程序:

<application>
    <view-handler>com.example.SomeViewHandler</view-handler>
</application>
Run Code Online (Sandbox Code Playgroud)

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

<lifecycle>
    <phase-listener>com.example.SomePhaseListener</phase-listener>
</lifecycle>
Run Code Online (Sandbox Code Playgroud)

无法注释的托管bean(下面给出了当前Date打开的#{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>
Run Code Online (Sandbox Code Playgroud)

定制工厂,如自定义异常处理程序工厂(这也让工厂进行FacesContext,ExternalContext,LifeCycle还有更多让你可以提供自定义实现):

<factory>
    <exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
</factory>
Run Code Online (Sandbox Code Playgroud)

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

  • @Matt:我有一个项目,其中`java.util.HashMap`作为`#{components }`存储在请求范围内,以便更好地声明所有组件绑定的概述.例如`binding ="#{components.foo}"`这样它就可以被引用为`#{components.foo}`,它比`binding ="#更自我记录,风险更小(由于潜在的名称冲突) {foo}"`和`#{foo}`. (7认同)
  • 我也在寻找一些注释来指定el-resolver.现在我认为没有办法通过注释来指定这些应用程序属性. (2认同)