What is the use of faces-config.xml in JSF 2?

After much support for JSF 2 annotations, I wonder why I will use faces-config.xml for. What is its importance now?

In other words, what are the configurations that can only be done through faces-config.xml and not through annotations?

Currently, all I use for this is declare Spring 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> 
+74
jsf jsf-2 faces-config
Sep 28 '11 at 12:13
source share
1 answer

It is still used for many things that cannot be annotated. For example. JSF custom check messages:

 <application> <message-bundle>com.example.i18n.messages</message-bundle> </application> 

The i18n global package (so you do not need to declare <f:loadBundle> in each view):

 <application> <resource-bundle> <base-name>com.example.i18n.Text</base-name> <var>text</var> </resource-bundle> </application> 

Explicitly supported i18n locales (so those that are not declared will be ignored, although there is a message package or resource package 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> 

Custom widget handlers :

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

Phase listeners (there is no annotation for this yet):

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

Managed beans that cannot be annotated (below is the current Date at #{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> 

Custom factories, such as a custom factory exception handler (it also allows FacesContext , ExternalContext , LifeCycle and much more so you can provide your own implementation):

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

Call only ordinary. If your IDE has a faces-config.xml autocomplete tag, you can find it all. Only managed beans, validators, converters, components, renderers, and point-to-point applications are no longer needed thanks to new annotations and implicit navigation.

+127
Sep 28 '11 at 13:01
source share



All Articles