title: How to set Locale in Bean Validation
body: <p>By default Bean Validation gets Locale based on Locale.getDefault(), which is common to whole JVM.</p>
  
  <p>How to change BeanValidation's Locale for current EJB method call?</p>
  
  <p>I'm using JavaEE7 and want to get benefits from integration of JPA and Bean Validation, i.e. automatic triggering validation on insert/update/delete events, and as far as possible avoid of writing everything manually.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After all, I'm just returning non-interpolated messages from EJB:</p>
  
  <pre><code>public class DoNothingMessageInterpolator implements MessageInterpolator {
      @Override
      public String interpolate(String message, Context context) {
          return message;
      }
      @Override
      public String interpolate(String message, Context context, Locale locale) {
          return message;
      }
  }
  </code></pre>
  
  <p>and later interpolating them in Web tier:</p>
  
  <pre><code>try{
      //invoke ejb
  }catch( EJBException ejbex ){
      if( ejbex.getCause() instanceof ConstraintViolationException ){
          ConstraintViolationException cve = (ConstraintViolationException) ejbex.getCause();
          WebUtils.printConstraintViolationMessages("NewConferenceForm:", context, cve, new Locale(languageCtrl.getLocaleCode()) );
          return null;
      }else throw ejbex;
  }catch( Exception e ){
          context.addMessage(null, new FacesMessage( FacesMessage.SEVERITY_ERROR, "Oops.", ""));
          return null;
  }
  
  
  public class WebUtils {
  
      public static void printConstraintViolationMessages(
          String formPrependId, 
          FacesContext context, 
          ConstraintViolationException cve,
          Locale locale )
      {
          Iterator&lt;ConstraintViolation&lt;?&gt;&gt; iter = cve.getConstraintViolations().iterator();
          while( iter.hasNext() ){
              final ConstraintViolation&lt;?&gt; cv = iter.next();
  
              javax.validation.MessageInterpolator.Context c = new javax.validation.MessageInterpolator.Context()
              {
                  @Override public &lt;T&gt; T unwrap(Class&lt;T&gt; type) {
                      try {
                          return type.newInstance();
                      } catch (InstantiationException ex) {
                          Logger.getLogger(ConferencesCtrl.class.getName()).log(Level.SEVERE, null, ex);
                      } catch (IllegalAccessException ex) {
                          Logger.getLogger(ConferencesCtrl.class.getName()).log(Level.SEVERE, null, ex);
                      }
                      return null;
                  }
                  @Override
                  public ConstraintDescriptor&lt;?&gt; getConstraintDescriptor() {
                      return cv.getConstraintDescriptor();
                  }
                  @Override
                  public Object getValidatedValue() {
                      return cv.getInvalidValue();
                  }
              };
  
              ResourceBundleMessageInterpolator rbmi = new ResourceBundleMessageInterpolator();
              String interpolatedMsg = rbmi.interpolate(cv.getMessage(), c, locale );
  
              //TODO: check if clientId exists
              context.addMessage( formPrependId+cv.getPropertyPath().toString(), new FacesMessage( interpolatedMsg ) );
          }
      }
  
  }
  </code></pre>