org.javalid.external.jsf
Class JsfMessageConverter

java.lang.Object
  extended by org.javalid.external.jsf.JsfMessageConverter

public class JsfMessageConverter
extends java.lang.Object

This class can be used to convert a standard List<ValidationMessage> result to JSF (Java Server Faces) messages. Note that when you use this class, JSF libraries must be present as dependencies.

Changes for 1.0.1:

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Method Summary
static void convertMessages(java.util.List<ValidationMessage> messages, javax.faces.context.FacesContext context)
          The most simplistic way to convert Jv validation messages to JSF messages.
static void convertMessages(java.util.List<ValidationMessage> messages, javax.faces.context.FacesContext context, java.lang.String bundleName)
          The most simplistic way to convert Jv validation messages to JSF messages.
static void convertMessages(java.util.List<ValidationMessage> messages, javax.faces.context.FacesContext context, java.lang.String parentViewId, boolean ignoreComponentNotFound, java.lang.String backingBeanName)
          Converts given validation messages to JSF messages.
static void convertMessages(java.util.List<ValidationMessage> messages, javax.faces.context.FacesContext context, java.lang.String parentViewId, boolean ignoreComponentNotFound, java.lang.String backingBeanName, java.lang.String bundleName)
          Converts given validation messages to JSF messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertMessages

public static final void convertMessages(java.util.List<ValidationMessage> messages,
                                         javax.faces.context.FacesContext context)
The most simplistic way to convert Jv validation messages to JSF messages. It does *not* take into account anything from the JSF environment, thus does not use any client-id's for the messages. Its best used for global type of messages. One pro though, it is fast. Gets the bundlename from the context!

Parameters:
messages - The validation messages to convert
context - The context to add the converted messages to

convertMessages

public static final void convertMessages(java.util.List<ValidationMessage> messages,
                                         javax.faces.context.FacesContext context,
                                         java.lang.String bundleName)
The most simplistic way to convert Jv validation messages to JSF messages.

Convenience method

It does *not* take into account anything from the JSF environment, thus does not use any client-id's for the messages. Its best used for global type of messages. One pro though, it is fast.

Parameters:
messages - The validation messages to convert
context - The context to add the converted messages to
bundleName - The fully qualified name of a property file (without .properties), is used for lookup of messages

convertMessages

public static final void convertMessages(java.util.List<ValidationMessage> messages,
                                         javax.faces.context.FacesContext context,
                                         java.lang.String parentViewId,
                                         boolean ignoreComponentNotFound,
                                         java.lang.String backingBeanName)
Converts given validation messages to JSF messages.

Convenience method

For docs check the other method with same parameters + bundleName. Use this method if this method must use the bundlename directly from the facesContext, the bundlename that is defined in your faces-config.xml

See Also:
convertMessages(List, FacesContext, String, boolean, String, String)

convertMessages

public static final void convertMessages(java.util.List<ValidationMessage> messages,
                                         javax.faces.context.FacesContext context,
                                         java.lang.String parentViewId,
                                         boolean ignoreComponentNotFound,
                                         java.lang.String backingBeanName,
                                         java.lang.String bundleName)
Converts given validation messages to JSF messages. The method uses the 'parentViewId' as its start location in the JSF component tree (locates it). Each validation message's path is used against UIComponents implementing the EditableValueHolder interface. If the path matches, the id of that component's id is added to the JSF message. If a path cannot be found for the components, a global JSF message is added if ignoreComponentNotFound=true, otherwise a JvException is raised telling which message could not be matched with a JSF component.

One exception to this rule, if ValidationMessage.isGlobalMessage() returns true it is immediately added as a global message, this could be the case if the user set a validation annotation's globalMessage to true (in all annotations that ship with the framework the default is false).

As your components in JSF pages bind to a backing bean for their values to store, it is recommended to specify the bean name, which makes matching faster and most of all: accurate. If not provided the matching is on a per 'guessing' base, which may be incorrect if you have for instance two backing beans used in the same JSF page like: beanName1, beanName2 and both have a property 'name' (to store something in). Without a beanName given the first match is the first component encountered in the JSF page using one of these beans. If you use just one backing bean in your JSF, this problem won't occur.

Parameters:
messages - The validation messages to convert
context - The context to use (and store messages to)
parentViewId - The id of a JSF component which contains the EditableValueHolder components to match a message against (all children, grandchildren etc. are searched for, so it is recommended to specify one which is close to these components, so no f:view for instance, which would be expensive!). The component itself is not used it self to match against. This id must be present.
ignoreComponentNotFound - If set to true, if for a validation path no component was found a JSF message without client id is added. If set to false an JvException is raised telling which component could not be found.
backingBeanName - The backingBeanName to use as a prefix, if you use multiple backingBeans in your page you can specify multiple names by separating them by a , . If left null, matching is done on a guessing base.
bundleName - The bundleName to use (to load a resource file to get the messages from)
Throws:
JavalidException - Raised if the parentViewId cannot be found or if ignoreComponentNotFound=false and a component could not be found for a message, a resource bundle is not present etc.