Author: alexsmirnov
Date: 2010-12-22 17:22:55 -0500 (Wed, 22 Dec 2010)
New Revision: 20753
Added:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/InitializationException.java
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
Log:
RESOLVED - issue RF-10066: richfaces-showcase: can't be run under latest code.
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2010-12-22
22:11:51 UTC (rev 20752)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2010-12-22
22:22:55 UTC (rev 20753)
@@ -25,15 +25,12 @@
import java.util.Map;
-import javax.validation.ValidationException;
-
import org.richfaces.el.ValueExpressionAnalayserImpl;
import org.richfaces.javascript.ClientScriptService;
import org.richfaces.javascript.ClientScriptServiceImpl;
import org.richfaces.javascript.ClientServiceConfigParser;
import org.richfaces.javascript.LibraryFunction;
import org.richfaces.validator.BeanValidator;
-import org.richfaces.validator.BeanValidatorFactory;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.BeanValidatorServiceImpl;
import org.richfaces.validator.ConverterServiceImpl;
@@ -41,6 +38,7 @@
import org.richfaces.validator.FacesConverterService;
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.FacesValidatorServiceImpl;
+import org.richfaces.validator.InitializationException;
import org.richfaces.validator.NullValidator;
import org.richfaces.validator.ObjectValidator;
import org.richfaces.validator.RichFacesBeanValidatorFactory;
@@ -80,10 +78,11 @@
BeanValidatorService service ;
ObjectValidator validator;
try {
- BeanValidatorFactory validatorFactory = new RichFacesBeanValidatorFactory();
+ RichFacesBeanValidatorFactory validatorFactory = new
RichFacesBeanValidatorFactory();
+ validatorFactory.init();
service = new BeanValidatorServiceImpl(new ValueExpressionAnalayserImpl(),
validatorFactory);
validator = new BeanValidator(validatorFactory);
- } catch (ValidationException e) {
+ } catch (InitializationException e) {
// JSR-303 is available but not initialised.
service = new DummyBeanValidatorService();
validator = new NullValidator();
Copied:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/InitializationException.java
(from rev 20751,
branches/4.0.0.M5/ui/validator/ui/src/main/java/org/richfaces/validator/InitializationException.java)
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/InitializationException.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/InitializationException.java 2010-12-22
22:22:55 UTC (rev 20753)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.validator;
+
+/**
+ * <p class="changed_added_4_0">Service initialization
exception.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+public class InitializationException extends Exception {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public InitializationException() {
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public InitializationException(String message) {
+ super(message);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public InitializationException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public InitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java 2010-12-22
22:11:51 UTC (rev 20752)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java 2010-12-22
22:22:55 UTC (rev 20753)
@@ -12,6 +12,7 @@
import javax.validation.MessageInterpolator;
import javax.validation.MessageInterpolator.Context;
import javax.validation.Validation;
+import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
@@ -19,46 +20,57 @@
/**
* @author asmirnov
- *
+ *
*/
public class RichFacesBeanValidatorFactory implements BeanValidatorFactory {
-
+
private ValidatorFactory validatorFactory;
private ValidatorContext validatorContext;
public RichFacesBeanValidatorFactory() {
// Enforce class to load
ValidatorFactory.class.getName();
+ }
+
+ public void init() throws InitializationException {
// Check Factory, to avoid instantiation errors
//
https://jira.jboss.org/jira/browse/RF-7226
- validatorFactory = Validation.buildDefaultValidatorFactory();
- validatorContext = validatorFactory.usingContext();
- MessageInterpolator jsfMessageInterpolator =
- new JsfMessageInterpolator(validatorFactory.getMessageInterpolator());
- validatorContext.messageInterpolator(jsfMessageInterpolator);
+ try {
+ validatorFactory = Validation.buildDefaultValidatorFactory();
+ validatorContext = validatorFactory.usingContext();
+ MessageInterpolator jsfMessageInterpolator =
+ new JsfMessageInterpolator(validatorFactory.getMessageInterpolator());
+ validatorContext.messageInterpolator(jsfMessageInterpolator);
+ } catch (ValidationException e) {
+ throw new InitializationException(e);
+ }
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.richfaces.validator.BeanValidatorFactory#getValidator(javax.faces.context.FacesContext)
*/
public Validator getValidator(FacesContext context) {
return validatorContext.getValidator();
}
-
- public FacesMessage interpolateMessage(FacesContext context,final
ConstraintDescriptor<? extends Annotation> constrain){
- if(constrain.getAttributes().containsKey("message")){
+
+ public FacesMessage interpolateMessage(FacesContext context,
+ final ConstraintDescriptor<? extends Annotation> constrain) {
+ if (constrain.getAttributes().containsKey("message")) {
Object object = constrain.getAttributes().get("message");
String interpolatedMessage;
- interpolatedMessage =
validatorFactory.getMessageInterpolator().interpolate(object.toString(), new Context() {
-
- public Object getValidatedValue() {
- return "{0}";
- }
-
- public ConstraintDescriptor<?> getConstraintDescriptor() {
- return constrain;
- }
- }, MessageFactory.getCurrentLocale(context));
+ interpolatedMessage =
+ validatorFactory.getMessageInterpolator().interpolate(object.toString(),
new Context() {
+
+ public Object getValidatedValue() {
+ return "{0}";
+ }
+
+ public ConstraintDescriptor<?> getConstraintDescriptor() {
+ return constrain;
+ }
+ }, MessageFactory.getCurrentLocale(context));
return new FacesMessage(interpolatedMessage);
} else {
return MessageFactory.createMessage(context, UIInput.UPDATE_MESSAGE_ID);
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-12-22
22:11:51 UTC (rev 20752)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-12-22
22:22:55 UTC (rev 20753)
@@ -54,6 +54,7 @@
@Before
public void setUp() throws Exception {
RichFacesBeanValidatorFactory validatorFactory = new
RichFacesBeanValidatorFactory();
+ validatorFactory.init();
validatorService = new BeanValidatorServiceImpl(analayser,validatorFactory);
expect(environment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);