首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >faces-config.xml在JSF2中的用途是什么?

faces-config.xml在JSF2中的用途是什么?
EN

Stack Overflow用户
提问于 2011-09-28 20:13:16
回答 1查看 80.6K关注 0票数 90

在JSF2对注解有了很大的支持之后,我想知道我要用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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-28 21:01:08

它仍然被用于许多无法注释的东西。例如,自定义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>

自定义view handlers

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

Phase listeners (目前还没有相应的注释):

<lifecycle>
    <phase-listener>com.example.SomePhaseListener</phase-listener>
</lifecycle>

不能注解的托管Date (下面的一个给出了#{now}上的当前bean):

<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和更多的工厂,以便您可以提供自定义实现):

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

仅列出常用的名称。如果你的集成开发环境中有faces-config.xml标签自动补全功能,你可以把它们都找出来。由于有了新的注释和隐式导航,只需要托管bean、验证器、转换器、组件、渲染器和点对点导航用例。

票数 143
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7583038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档