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

前端之家收集整理的这篇文章主要介绍了在JSF 2中使用faces-config.xml是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
JSF 2大的支持注释后,我想知道我会使用faces-config.xml。它现在的重要性是什么?

换句话说,什么配置只能通过faces-config.xml而不是通过注释来完成?

现在我使用它的所有的是声明Spring的EL解析器。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <faces-config
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  6. http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
  7. version="2.0">
  8.  
  9. <application>
  10. <el-resolver>
  11. org.springframework.web.jsf.el.SpringBeanFacesELResolver
  12. </el-resolver>
  13. </application>
  14. </faces-config>
它仍然被用于许多无法注释的事情。例如。自定义JSF验证消息:
  1. <application>
  2. <message-bundle>com.example.i18n.messages</message-bundle>
  3. </application>

全局i18n软件包(以便您不需要在每个视图中声明< f:loadBundle>):

  1. <application>
  2. <resource-bundle>
  3. <base-name>com.example.i18n.Text</base-name>
  4. <var>text</var>
  5. </resource-bundle>
  6. </application>

显式支持i18n区域(所以即使有消息包或资源束,也会忽略未声明的区域):

  1. <application>
  2. <locale-config>
  3. <default-locale>en</default-locale>
  4. <supported-locale>nl</supported-locale>
  5. <supported-locale>es</supported-locale>
  6. <supported-locale>de</supported-locale>
  7. </locale-config>
  8. </application>

自定义view handlers

  1. <application>
  2. <view-handler>com.example.SomeViewHandler</view-handler>
  3. </application>

Phase listeners(仍然没有注释):

  1. <lifecycle>
  2. <phase-listener>com.example.SomePhaseListener</phase-listener>
  3. </lifecycle>

无法注释的托管bean(下面的#提供了#{now}的当前日期):

  1. <managed-bean>
  2. <description>Current date and time</description>
  3. <managed-bean-name>now</managed-bean-name>
  4. <managed-bean-class>java.util.Date</managed-bean-class>
  5. <managed-bean-scope>request</managed-bean-scope>
  6. </managed-bean>

自定义工厂,如自定义异常处理程序工厂(它也允许工厂为FacesContextExternalContextLifeCycle等等,以便您可以提供您的自定义实现):

  1. <factory>
  2. <exception-handler-factory>com.example.SomeExceptionHandlerFactory</exception-handler-factory>
  3. </factory>

只列出常用的。如果你在IDE中有faces-config.xml标签自动完成,你可以找到它们。由于新的注释和隐式导航,只需要被管理的bean,验证器,转换器,组件,渲染器和点对点导航情况。

猜你在找的XML相关文章