myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Extensions/Validator/JSR303/Advanced" by GerhardPetracek
Date Fri, 12 Mar 2010 14:55:44 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The "Extensions/Validator/JSR303/Advanced" page has been changed by GerhardPetracek.
http://wiki.apache.org/myfaces/Extensions/Validator/JSR303/Advanced?action=diff&rev1=3&rev2=4

--------------------------------------------------

  
  Mapping to custom implementations is supported (to get rid of import statements of ExtVal
classes).
  
+ == JSF Messages ==
+ It's not nice to have messages in different places.
+ Instead of tweaking BV itself, ExtVal provides a mechanism to resolve the message from a
different location.
+ By default BV just knows the bundle: ValidationMessages in the root package.
+ 
+ However, since we are in a JSF application you might already have a message bundle for your
messages.<<BR>>
+ E.g.:
+ {{{
+ <application>
+     <resource-bundle>
+         <base-name>org.apache.myfaces.demo.app_messages</base-name>
+         <var>app_messages</var>
+     </resource-bundle>
+ </application>
+ }}}
+ 
+ To join these messages for your BV violation messages you just have to use the following
code in a custom extval-startup listener:
+ {{{
+ StaticInMemoryConfiguration config = new StaticInMemoryConfiguration();
+ config.addMapping(BeanValidationVirtualValidationStrategy.class.getName(), JsfAwareMessageResolver.class.getName());
+ ExtValContext.getContext().addStaticConfiguration(StaticConfigurationNames.VALIDATION_STRATEGY_TO_MESSAGE_RESOLVER_CONFIG,
config);
+ }}}
+ 
+ The implementation of the message resolver is quite easy:
+ {{{
+ import org.apache.myfaces.extensions.validator.core.validation.message.resolver.DefaultValidationErrorMessageResolver;
+ 
+ public class JsfAwareMessageResolver extends DefaultValidationErrorMessageResolver{
+     public ApplicationMessageBundleAwareMessageResolver() {
+         setMessageBundleVarName("messages");
+     }
+ }
+ }}}
+ ... as alternative for using the fully qualified resource-bundle you can also use the method
setMessageBundleBaseName.
+ 
+ As '''alternative''' for an easier configuration, you can use one of the config add-ons
e.g. provided by [[http://os890.googlecode.com/|os890]].
+ 
  == BV Classes Only ==
  
  If the sw-architecture of your application restricts the usage of ExtVal outside the View-Layer
it's possible to map the default implementations to custom implementations. That means: The
mapping takes place at startup (in the View-Layer) and in all classes outside the startup-listener
you can use your custom implementations.

Mime
View raw message