[seam-commits] Seam SVN: r12683 - in modules/faces/trunk: docs/reference/src/main/docbook/en-US and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed May 5 19:05:47 EDT 2010


Author: lincolnthree
Date: 2010-05-05 19:05:46 -0400 (Wed, 05 May 2010)
New Revision: 12683

Added:
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationTypeOverrideExtension.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerAccessor.java
Modified:
   modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/validation/InputField.java
   modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerUtils.java
   modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
   modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
* Committing cross-field-validation v2 - still writing tests.

Modified: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/validation/InputField.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/validation/InputField.java	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/validation/InputField.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -22,6 +22,7 @@
 package org.jboss.seam.faces.validation;
 
 import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -98,7 +99,7 @@
  */
 @Qualifier
 @Retention(RUNTIME)
- at Target( { FIELD })
+ at Target( { FIELD, METHOD })
 public @interface InputField
 {
    @Nonbinding

Modified: modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml
===================================================================
--- modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/docs/reference/src/main/docbook/en-US/components.xml	2010-05-05 23:05:46 UTC (rev 12683)
@@ -22,7 +22,7 @@
       xmlns:s="http://jboss.com/products/seam/faces"
       xmlns:ui="http://java.sun.com/jsf/facelets">
       
-      <h1>This is a page using Seam Faces</h1>
+      <h1>This is a view using Seam Faces</h1>
       <h:outputText value="#{bean.sayHello()}" />
       
 </html>]]></programlisting>
@@ -37,7 +37,11 @@
 	<section id="validateForm">
 		<title>&lt;s:validateForm&gt;</title>
 		<para>
-			Performing cross-field form validation is simple using the Form Validation component.
+			On many occasions you might find yourself needing to compare the values of multiple input fields
+			on a given page submit: confirming a password; re-enter password; address lookups; and so on. 
+			
+			Performing cross-field form validation is simple - just place the &lt;s:validateForm&gt; component
+			in the form you wish to validate, then attach your custom Validator.
 			<programlisting><![CDATA[<h:form id="locationForm">
      <h:inputText id="city" value="#{bean.author}" />
      <h:inputText id="state" value="#{bean.title}" />
@@ -56,32 +60,48 @@
    @Inject
    Directory directory;
 
+   @Inject
    @InputField
-   private String city;
+   private Object city;
 
+   @Inject
    @InputField
-   private String state;
+   private Object state;
 
+   @Inject
    @InputField
-   private String zip;
+   private ZipCode zip;
 
    @Override
    public void validate(final FacesContext context, final UIComponent comp, final Object values) throws ValidatorException
    {
       if(!directory.exists(city, state, zip))
       {
-         throw new ValidatorException(new FacesMessage("Multiple fields-- failed validation baby!"));
+         throw new ValidatorException(new FacesMessage("Sorry, that location is not in our database. Please try again."));
       }
    }
 }</programlisting>
-
-
-
+		</para>
+		
+			<tip>
+				<para>
+		You may inject the correct type directly.
+				<programlisting>@Inject
+ at InputField
+private ZipCode zip;</programlisting>
+				</para>
+			</tip>
+		
+		<para>
 			Notice that the IDs of the inputText components match the IDs of your Validator 
-			@InputFields. The name of the @InputField will automatically
+			@InputFields; each @Inject @InputField member will be injected with the value of the form input field
+			who's ID matches the name of the variable.
+		</para>
+		<para>
+			In other words - the name of the @InputField annotated member variable will automatically
 			be matched to the ID of the input component, unless overridden by using a field
-			ID alias (see below.) Notice that "zip" will still be referenced normally; you need only
-			specify aliases for fields that differ in name from the Validator @InputFields.
+			ID alias (see below.) 
+			
 			<programlisting><![CDATA[<h:form id="locationForm">
      <h:inputText id="cityId" value="#{bean.author}" />
      <h:inputText id="stateId" value="#{bean.title}" />
@@ -91,9 +111,29 @@
       <s:validateForm fields="city=cityId state=stateId" validatorId="locationValidator" />
 </h:form>]]></programlisting>
 
+			Notice that "zip" will still be referenced normally; you need only
+			specify aliases for fields that differ in name from the Validator @InputFields.
+			
+		</para>
+		<para>
 
+			<tip>
+				<para>
+					<literal>Using @InputField("customID")</literal> with an ID override can also be used to 
+					specify a custom ID, instead of using the default: the name of the field. This gives you
+					the ability to change the name of the private field, without worrying about changing the
+					name of input fields in the View itself.
+				<programlisting>@Inject
+ at InputField("state")
+private String sectorTwo;</programlisting>
+				</para>
+			</tip>
 		</para>
 	</section>
+	
+	
+	
+	
 	<section id="viewaction">
 		<title>&lt;s:viewAction&gt;</title>
 		<para>

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationFieldProducer.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -0,0 +1,189 @@
+/*
+ * 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.jboss.seam.faces.component;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.inject.Inject;
+
+import org.jboss.seam.faces.event.qualifier.After;
+import org.jboss.seam.faces.event.qualifier.Before;
+import org.jboss.seam.faces.validation.InputField;
+import org.slf4j.Logger;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+ at RequestScoped
+public class FormValidationFieldProducer
+{
+   @Inject
+   Logger log;
+
+   @Inject
+   FacesContext context;
+
+   UIForm form = null;
+   UIValidateForm validator = null;
+   private Map<String, UIInput> components = null;
+
+   public void interceptComponentTree(@Observes @Before final UIValidateForm event)
+   {
+      validator = event;
+      form = locateForm(event);
+      components = locateAliasedComponents(event);
+   }
+
+   public void cleanupComponentTree(@Observes @After final UIValidateForm event)
+   {
+      components = new HashMap<String, UIInput>();
+   }
+
+   @Produces
+   @Dependent
+   @InputField
+   public Object getInputFieldValue(final InjectionPoint ip)
+   {
+      Object result = null;
+
+      if (isInitialized())
+      {
+         String id = getFieldId(ip);
+         UIInput component = findComponent(id, id);
+         components.put(id, component);
+
+         if (component.isLocalValueSet())
+         {
+            result = component.getValue();
+         }
+         else
+         {
+            Converter converter = component.getConverter();
+            if (converter != null)
+            {
+               result = converter.getAsObject(context, component, (String) component.getSubmittedValue());
+            }
+            else
+            {
+               result = component.getSubmittedValue();
+            }
+         }
+
+      }
+
+      return result;
+   }
+
+   private boolean isInitialized()
+   {
+      return form != null;
+   }
+
+   private String getFieldId(final InjectionPoint ip)
+   {
+      String parameterName = ip.getAnnotated().getAnnotation(InputField.class).value();
+      if ("".equals(parameterName))
+      {
+         parameterName = ip.getMember().getName();
+      }
+      return parameterName;
+   }
+
+   private UIForm locateForm(final UIComponent component)
+   {
+      UIComponent parent = component.getParent();
+      while (!(parent instanceof UIForm))
+      {
+         parent = parent.getParent();
+         if ((parent == null) || (parent instanceof UIViewRoot))
+         {
+            throw new IllegalStateException("The form validator must be placed within a UIForm");
+         }
+      }
+      return (UIForm) parent;
+   }
+
+   public HashMap<String, UIInput> locateAliasedComponents(final UIValidateForm validator)
+   {
+      HashMap<String, UIInput> result = new HashMap<String, UIInput>();
+      String fields = validator.getFields();
+      if ((fields != null) && !"".equals(fields.trim()))
+      {
+         List<String> clientFieldIds = Arrays.asList(fields.split("\\s+"));
+         for (String field : clientFieldIds)
+         {
+            List<String> mapping = Arrays.asList(field.split("\\s*=\\s*"));
+            String aliasFieldName = mapping.get(0);
+
+            String clientInputId = aliasFieldName;
+
+            if (mapping.size() > 1)
+            {
+               clientInputId = mapping.get(1);
+            }
+
+            UIInput component = findComponent(aliasFieldName, clientInputId);
+            components.put(aliasFieldName, component);
+         }
+      }
+      return result;
+   }
+
+   private UIInput findComponent(final String alias, final String clientId)
+   {
+      UIComponent comp = null;
+      if (!components.containsKey(clientId))
+      {
+         comp = form.findComponent(clientId);
+         if (!(comp instanceof UIInput))
+         {
+            throw new IllegalArgumentException("Component [" + form.getClientId() + ":" + alias + "] must be a UIInput component.");
+         }
+         else if (comp == null)
+         {
+            throw new IllegalArgumentException("Could not locate component [" + form.getClientId() + ":" + alias + "]");
+         }
+      }
+      else
+      {
+         comp = components.get(clientId);
+      }
+      return (UIInput) comp;
+   }
+
+}

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationTypeOverrideExtension.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationTypeOverrideExtension.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/FormValidationTypeOverrideExtension.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -0,0 +1,82 @@
+/*
+ * 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.jboss.seam.faces.component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.jboss.seam.faces.validation.InputField;
+import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
+
+/**
+ * Ensure that any field annotated with {@link InputField} is produced by the
+ * same producer method with output type {@link Object}.
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+ at ApplicationScoped
+public class FormValidationTypeOverrideExtension implements Extension
+{
+   private final Map<Class<?>, AnnotatedType<?>> typeOverrides = new HashMap<Class<?>, AnnotatedType<?>>();
+
+   public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event)
+   {
+      AnnotatedTypeBuilder<T> builder = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType());
+      builder.readAnnotationsFromUnderlyingType();
+      boolean modifiedType = false;
+
+      for (AnnotatedField<?> f : event.getAnnotatedType().getFields())
+      {
+         if (f.isAnnotationPresent(InputField.class))
+         {
+            builder.overrideFieldType(f.getJavaMember(), Object.class);
+            modifiedType = true;
+         }
+      }
+
+      if (modifiedType)
+      {
+         AnnotatedType<T> replacement = builder.create();
+         typeOverrides.put(replacement.getJavaClass(), replacement);
+         event.setAnnotatedType(replacement);
+      }
+   }
+
+   public boolean hasOverriddenType(final Class<?> clazz)
+   {
+      return typeOverrides.containsKey(clazz);
+   }
+
+   public AnnotatedType<?> getOverriddenType(final Class<?> clazz)
+   {
+      return typeOverrides.get(clazz);
+   }
+}

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/component/UIValidateForm.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -23,23 +23,23 @@
 package org.jboss.seam.faces.component;
 
 import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
+import javax.enterprise.util.AnnotationLiteral;
 import javax.faces.component.FacesComponent;
 import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
 import javax.faces.component.UIInput;
-import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
+import javax.faces.event.PostValidateEvent;
+import javax.faces.event.PreValidateEvent;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
 
+import org.jboss.seam.faces.event.qualifier.After;
+import org.jboss.seam.faces.event.qualifier.Before;
+import org.jboss.seam.faces.util.BeanManagerAccessor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,6 +50,15 @@
 @FacesComponent(UIValidateForm.COMPONENT_TYPE)
 public class UIValidateForm extends UIInput
 {
+   private static final AnnotationLiteral<Before> BEFORE = new AnnotationLiteral<Before>()
+   {
+      private static final long serialVersionUID = 7631699535063526392L;
+   };
+   private static final AnnotationLiteral<After> AFTER = new AnnotationLiteral<After>()
+   {
+      private static final long serialVersionUID = -929128236303355107L;
+   };
+
    public static final String COMPONENT_TYPE = "org.jboss.seam.faces.ValidateForm";
    public static final String COMPONENT_FAMILY = "org.jboss.seam.faces.ValidateForm";
 
@@ -69,15 +78,8 @@
    @Override
    public void validate(final FacesContext context)
    {
-      UIComponent parent = this.getParent();
-      while (!(parent instanceof UIForm))
-      {
-         parent = parent.getParent();
-         if ((parent == null) || (parent instanceof UIViewRoot))
-         {
-            throw new IllegalStateException("The form validator must be placed within a UIForm");
-         }
-      }
+      context.getApplication().publishEvent(context, PreValidateEvent.class, UIValidateForm.class, this);
+      BeanManagerAccessor.getManager().fireEvent(this, BEFORE);
 
       Validator validator = context.getApplication().createValidator(validatorId);
       if (validator == null)
@@ -87,110 +89,21 @@
 
       try
       {
-         locateComponents(validator, parent, fields);
-         injectFieldValues(validator, context);
+         UIComponent parent = this.getParent();
          validator.validate(context, parent, components);
       }
       catch (ValidatorException e)
       {
+         // TODO fire components invalid event
          setComponentsInvalid();
          setValid(false);
          context.addMessage(null, e.getFacesMessage());
       }
-   }
 
-   public void locateComponents(final Validator validator, final UIComponent component, final String fields)
-   {
-      UIForm form = (UIForm) component;
-
-      List<String> validatorFieldIds = getValidatorFieldNames(validator);
-
-      if ((fields != null) && !"".equals(fields.trim()))
-      {
-         List<String> clientFieldIds = Arrays.asList(fields.split("\\s+"));
-         for (String field : clientFieldIds)
-         {
-            List<String> mapping = Arrays.asList(field.split("\\s*=\\s*"));
-            String clientValidatorFieldId = mapping.get(0);
-            if (validatorFieldIds.contains(clientValidatorFieldId))
-            {
-               validatorFieldIds.remove(clientValidatorFieldId);
-            }
-            else
-            {
-               throw new IllegalArgumentException("Unknown field: [" + field + "] for Validator of type: " + validator.getClass().getName() + ", expected fields: " + getValidatorFieldNames(validator));
-            }
-
-            String clientFieldId = clientValidatorFieldId;
-
-            if (mapping.size() > 1)
-            {
-               clientFieldId = mapping.get(1);
-            }
-
-            UIComponent comp = form.findComponent(clientFieldId);
-            if ((comp != null) && (comp instanceof UIInput))
-            {
-               components.put(clientValidatorFieldId, (UIInput) comp);
-            }
-            else
-            {
-               log.warn("Could not locate component in form [" + form.getClientId() + ":" + clientValidatorFieldId + "]");
-            }
-         }
-      }
-
-      for (String field : validatorFieldIds)
-      {
-         UIComponent comp = form.findComponent(field);
-         if ((comp != null) && (comp instanceof UIInput))
-         {
-            components.put(field, (UIInput) comp);
-         }
-         else
-         {
-            log.warn("Could not locate component in form [" + form.getClientId() + ":" + field + "] while processing Validator:" + validator.getClass().getName());
-         }
-      }
+      BeanManagerAccessor.getManager().fireEvent(this, AFTER);
+      context.getApplication().publishEvent(context, PostValidateEvent.class, UIValidateForm.class, this);
    }
 
-   private void injectFieldValues(final Validator validator, final FacesContext context)
-   {
-      Field[] declaredFields = validator.getClass().getDeclaredFields();
-      for (Field f : declaredFields)
-      {
-         String name = getFieldName(f);
-
-         boolean restricted = false;
-         if (!f.isAccessible())
-         {
-            restricted = true;
-            f.setAccessible(true);
-         }
-
-         try
-         {
-            UIInput input = components.get(name);
-            if (input != null)
-            {
-               Object value = input.getValue();
-               f.set(validator, value);
-            }
-         }
-         catch (Exception e)
-         {
-            throw new RuntimeException("Could not inject value into validator: " + validator.getClass().getName(), e);
-         }
-
-         if (restricted)
-         {
-            f.setAccessible(false);
-         }
-      }
-
-      return;
-   }
-
    private void setComponentsInvalid()
    {
       for (UIComponent comp : components.values())
@@ -203,34 +116,6 @@
       }
    }
 
-   private List<String> getValidatorFieldNames(final Validator validator)
-   {
-      List<String> result = new ArrayList<String>();
-      Field[] declaredFields = validator.getClass().getDeclaredFields();
-      for (Field f : declaredFields)
-      {
-         if (f.isAnnotationPresent(org.jboss.seam.faces.validation.InputField.class))
-         {
-            result.add(getFieldName(f));
-         }
-      }
-      return result;
-   }
-
-   private String getFieldName(final Field f)
-   {
-      String name = "";
-      if (f.isAnnotationPresent(org.jboss.seam.faces.validation.InputField.class))
-      {
-         name = f.getAnnotation(org.jboss.seam.faces.validation.InputField.class).value();
-      }
-      if ("".equals(name))
-      {
-         name = f.getName();
-      }
-      return name;
-   }
-
    /*
     * Prevent any rendered output.
     */

Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerAccessor.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerAccessor.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerAccessor.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -0,0 +1,43 @@
+/*
+ * 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.jboss.seam.faces.util;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.weld.extensions.beanManager.BeanManagerAware;
+
+/**
+ * <b>***DO NOT USE THIS CLASS***</b>
+ * <p>
+ * See {@link BeanManagerAware}
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ * 
+ */
+public class BeanManagerAccessor extends BeanManagerAware
+{
+   public static BeanManager getManager()
+   {
+      return new BeanManagerAccessor().getBeanManager();
+   }
+}

Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerUtils.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerUtils.java	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/util/BeanManagerUtils.java	2010-05-05 23:05:46 UTC (rev 12683)
@@ -27,11 +27,14 @@
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.inject.Inject;
 
+import org.jboss.seam.faces.component.FormValidationTypeOverrideExtension;
+
 /**
  * A utility providing common functions to simply use of {@link BeanManager}
  * 
@@ -43,6 +46,9 @@
    @Inject
    private BeanManager manager;
 
+   @Inject
+   FormValidationTypeOverrideExtension classExtension;
+
    /**
     * Perform @{@link Inject} on an object as if it were a bean managed by CDI.
     * 
@@ -54,11 +60,25 @@
       if (instance != null)
       {
          CreationalContext<Object> creationalContext = manager.createCreationalContext(null);
-         InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) manager.createInjectionTarget(manager.createAnnotatedType(instance.getClass()));
+         InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) manager.createInjectionTarget(getAnnotatedType(instance));
          injectionTarget.inject(instance, creationalContext);
       }
    }
 
+   private AnnotatedType<? extends Object> getAnnotatedType(final Object instance)
+   {
+      AnnotatedType<?> result = null;
+      if (classExtension.hasOverriddenType(instance.getClass()))
+      {
+         result = classExtension.getOverriddenType(instance.getClass());
+      }
+      else
+      {
+         result = manager.createAnnotatedType(instance.getClass());
+      }
+      return result;
+   }
+
    @SuppressWarnings("unchecked")
    public <T> boolean isDependentScoped(final Class<T> type)
    {

Modified: modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/faces-config.xml	2010-05-05 23:05:46 UTC (rev 12683)
@@ -46,6 +46,10 @@
 			<system-event-listener-class>org.jboss.seam.faces.event.DelegatingSystemEventListener</system-event-listener-class>
 			<system-event-class>javax.faces.event.PreRenderViewEvent</system-event-class>
 		</system-event-listener>
+		<system-event-listener>
+			<system-event-listener-class>org.jboss.seam.faces.event.DelegatingSystemEventListener</system-event-listener-class>
+			<system-event-class>javax.faces.event.PreValidateEvent</system-event-class>
+		</system-event-listener>
 	</application>
 
 </faces-config>
\ No newline at end of file

Modified: modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension	2010-05-04 20:47:47 UTC (rev 12682)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension	2010-05-05 23:05:46 UTC (rev 12683)
@@ -1,3 +1,4 @@
+org.jboss.seam.faces.component.FormValidationTypeOverrideExtension
 org.jboss.seam.faces.context.ViewScopedExtension
 org.jboss.seam.faces.context.FlashScopedExtension
 org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension



More information about the seam-commits mailing list