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>
Phase listeners(仍然没有注释):
- <lifecycle>
- <phase-listener>com.example.SomePhaseListener</phase-listener>
- </lifecycle>
无法注释的托管bean(下面的#提供了#{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>
自定义工厂,如自定义异常处理程序工厂(它也允许工厂为FacesContext
,ExternalContext
,LifeCycle
等等,以便您可以提供您的自定义实现):
- <factory>
- <exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
- </factory>
只列出常用的。如果你在IDE中有faces-config.xml标签自动完成,你可以找到它们。由于新的注释和隐式导航,只需要被管理的bean,验证器,转换器,组件,渲染器和点对点导航情况。