JSF 2 中faces-config.xml 的用途是什么? [英] What is the use of faces-config.xml in JSF 2?
问题描述
在 JSF 2 对注解的大力支持之后,我想知道我会用 faces-config.xml
做什么.它现在的重要性是什么?
After the JSF 2 big support for annotations, I'm wondering what I would use the faces-config.xml
for. What is its importance now?
也就是说,有哪些配置只能通过faces-config.xml
进行,不能通过注解?
In other words, what are the configurations that can only be done through faces-config.xml
and not via annotations?
现在我使用它的目的就是声明 Spring 的 EL 解析器.
Right now all what I am using it for is to declare Spring's EL resolver.
<?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 验证消息:
It's still to be used for many things which can't be annotated. E.g. custom JSF validation messages:
<application>
<message-bundle>com.example.i18n.messages</message-bundle>
</application>
一个全局 i18n 包(这样你就不需要在每个视图中声明
):
A global i18n bundle (so that you don't need to declare <f:loadBundle>
in every view):
<application>
<resource-bundle>
<base-name>com.example.i18n.Text</base-name>
<var>text</var>
</resource-bundle>
</application>
显式支持 i18n 语言环境(这样即使有消息包或资源包,未声明的也将被忽略):
Explicitly supported i18n locales (so that the not-declared ones will be ignored even though there's a message bundle or resource bundle for it):
<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(下面给出了#{now}
上的当前Date
):
Managed beans which can't be annotated (the below one gives current Date
on #{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
等等,以便您可以提供自定义实现):
Custom factories, such as custom exception handler factory (it also allows factories for FacesContext
, ExternalContext
, LifeCycle
and many more so that you can provide your custom implementation):
<factory>
<exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
</factory>
仅列举常用的.如果您的 IDE 中有 faces-config.xml
标记自动完成功能,您可以找到它们.由于新的注释和隐式导航,仅不再需要托管 bean、验证器、转换器、组件、渲染器和点对点导航案例.
To name only the commonly used ones. If you have faces-config.xml
tag autocompletion in your IDE, you can find them all out. Only the managed beans, validators, converters, components, renderers and point-to-point navigation cases are not needed anymore thanks to the new annotations and implicit navigation.
这篇关于JSF 2 中faces-config.xml 的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!