org.javalid.external.jsf
Class JvJsfContextListener

java.lang.Object
  extended by org.javalid.external.jsf.JvJsfContextListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public class JvJsfContextListener
extends java.lang.Object
implements javax.servlet.ServletContextListener

Use this context listener to store both the AnnotationValidator and the JvJsfConfiguration instance in the servlet context. The UpdateValuesPhaseListener does depend on this (if you use it).

AnnotationValidator is stored under the key 'JsfFacadeShared.KEY_ANNOTATION_VALIDATOR_LOCATION'. JvJsfConfiguration is stored under JsfFacadeShared.KEY_JSF_CONFIGURATION_LOCATION (if and only if you don't use the useBean option).

The listener expects an init-parameter in the web.xml file named: 'jv-jsf-config-file' containing the full path of the xml configuration file for jsf support.

To load the annotation validator specify an xml file by init-parameter: 'jv-config-file', else a default AnnotationValidator config file is used.

Finally to use a different AnnotationValidator there are two ways:

1) You can specify jv-validator-class in the web.xml as init-parameter telling what class to use. Note the validator must have at least 1 parameter representing the xmlConfigFile to use to load (java.lang.String). The optional second parameter is:
jv-value-to-null-if-empty: either true or false. If true, String / StringBuffer values being bound on an object, if they are empty "" (jsf mostly submits empty values of users as "" instead of null) are set to NULL during validation (not on the object itself) to prevent firing other validation annotations. This latter is an old feature (and may be removed in the future), you'd best off to use the @NotEmpty annotation on your model objects instead of @NotNull. This is relevant for non-required fields. By default the annotationvalidator sets this option to false (default framework behavior), override it here if needed.

2) Specify the jv-use-bean init parameter in web.xml, and set it to true. By doing so you must also specify the jv-bean-name parameter to tell what bean to use defined in either Spring or JSF e.g. myValidator (if the bean is called that way). The framework will first attempt to find it in Spring (if you have that on your classpath) and if that isnt there (or fails) attempts to find it using the JSF EL resolver.

Changes for 1.0.1:

Changes for 1.1:

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Field Summary
static java.lang.String JV_ANNOTATION_USE_BEAN_INIT_PARAM
          Servlet init parameter name (web.xml), denoting if a Spring bean must be specified or the normal jv-validator-class.
static java.lang.String JV_ANNOTATION_VALIDATOR_BEAN_CLASS_INIT_PARAM
          Servlet init parameter name (web.xml), denoting which bean must be found (in Spring WebApplicationContext or JSF EL context, both are tried in that order if available).
static java.lang.String JV_ANNOTATION_VALIDATOR_CONFIG_FILE_INIT_PARAM
          Servlet init parameter name (web.xml), the value should tell what JV config file to use (full path).
static java.lang.String JV_ANNOTATION_VALIDATOR_IMPLEMENTATION_CLASS_INIT_PARAM
          Servlet init parameter name (web.xml), denoting which AnnotationValidator class must be instantiated (and stored in the servlet context).
static java.lang.String JV_JSF_CONFIG_FILE_INIT_PARAM
          Servlet init parameter name (web.xml), the value should tell what config file to use (full path).
static java.lang.String JV_VALUE_TO_NULL_FOR_EMPTY_STRING_INIT_PARAM
          Servlet init parameter name (web.xml), denoting whether to set empty string/stringbuffer values to null during validation.
 
Constructor Summary
JvJsfContextListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent event)
           
 void contextInitialized(javax.servlet.ServletContextEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JV_JSF_CONFIG_FILE_INIT_PARAM

public static final java.lang.String JV_JSF_CONFIG_FILE_INIT_PARAM
Servlet init parameter name (web.xml), the value should tell what config file to use (full path). REQUIRED.

See Also:
Constant Field Values

JV_ANNOTATION_VALIDATOR_CONFIG_FILE_INIT_PARAM

public static final java.lang.String JV_ANNOTATION_VALIDATOR_CONFIG_FILE_INIT_PARAM
Servlet init parameter name (web.xml), the value should tell what JV config file to use (full path). OPTIONAL. If not specified falls back to the default JV config file.

See Also:
Constant Field Values

JV_ANNOTATION_VALIDATOR_IMPLEMENTATION_CLASS_INIT_PARAM

public static final java.lang.String JV_ANNOTATION_VALIDATOR_IMPLEMENTATION_CLASS_INIT_PARAM
Servlet init parameter name (web.xml), denoting which AnnotationValidator class must be instantiated (and stored in the servlet context). OPTIONAL. If not provided, loads default AnnotationValidationImpl class.

See Also:
Constant Field Values

JV_ANNOTATION_VALIDATOR_BEAN_CLASS_INIT_PARAM

public static final java.lang.String JV_ANNOTATION_VALIDATOR_BEAN_CLASS_INIT_PARAM
Servlet init parameter name (web.xml), denoting which bean must be found (in Spring WebApplicationContext or JSF EL context, both are tried in that order if available). OPTIONAL.

See Also:
Constant Field Values

JV_ANNOTATION_USE_BEAN_INIT_PARAM

public static final java.lang.String JV_ANNOTATION_USE_BEAN_INIT_PARAM
Servlet init parameter name (web.xml), denoting if a Spring bean must be specified or the normal jv-validator-class. This parameter is optional, and if not set jv-validator-class is expected. Value true or false.

See Also:
Constant Field Values

JV_VALUE_TO_NULL_FOR_EMPTY_STRING_INIT_PARAM

public static final java.lang.String JV_VALUE_TO_NULL_FOR_EMPTY_STRING_INIT_PARAM
Servlet init parameter name (web.xml), denoting whether to set empty string/stringbuffer values to null during validation. See comment of this class for more info. OPTIONAL. If not provided, does not reset values to null if empty during validation. Value must be true / false.

See Also:
Constant Field Values
Constructor Detail

JvJsfContextListener

public JvJsfContextListener()
Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent event)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener