Return-Path: X-Original-To: apmail-deltaspike-commits-archive@www.apache.org Delivered-To: apmail-deltaspike-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 27A9C102FC for ; Sun, 13 Oct 2013 15:49:17 +0000 (UTC) Received: (qmail 10347 invoked by uid 500); 13 Oct 2013 15:49:16 -0000 Delivered-To: apmail-deltaspike-commits-archive@deltaspike.apache.org Received: (qmail 10308 invoked by uid 500); 13 Oct 2013 15:49:13 -0000 Mailing-List: contact commits-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltaspike.apache.org Delivered-To: mailing list commits@deltaspike.apache.org Received: (qmail 10301 invoked by uid 99); 13 Oct 2013 15:49:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Oct 2013 15:49:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F0BA383883C; Sun, 13 Oct 2013 15:49:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gpetracek@apache.org To: commits@deltaspike.apache.org Message-Id: <8d94a87299684a6eb69c52e76ceb61a4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: DELTASPIKE-426 support for cdi beans as jsf converters and validators Date: Sun, 13 Oct 2013 15:49:11 +0000 (UTC) Updated Branches: refs/heads/master 403ce9425 -> b209f589a DELTASPIKE-426 support for cdi beans as jsf converters and validators Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b209f589 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b209f589 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b209f589 Branch: refs/heads/master Commit: b209f589aaee5604ce01cb646118a2a43a08c5a9 Parents: 403ce94 Author: gpetracek Authored: Sun Oct 13 16:46:46 2013 +0200 Committer: gpetracek Committed: Sun Oct 13 17:42:09 2013 +0200 ---------------------------------------------------------------------- .../jsf/api/config/JsfModuleConfig.java | 18 +++ .../jsf/impl/injection/AbstractBeanStorage.java | 54 +++++++++ .../AbstractContextualReferenceWrapper.java | 100 +++++++++++++++++ .../jsf/impl/injection/ConverterWrapper.java | 44 ++++++++ .../jsf/impl/injection/DependentBeanEntry.java | 54 +++++++++ .../InjectionAwareApplicationWrapper.java | 111 +++++++++++++++++++ .../impl/injection/ManagedArtifactResolver.java | 102 +++++++++++++++++ .../injection/RequestDependentBeanStorage.java | 26 +++++ .../jsf/impl/injection/ValidatorWrapper.java | 38 +++++++ .../injection/ViewDependentBeanStorage.java | 28 +++++ .../request/DeltaSpikeFacesContextWrapper.java | 16 +++ 11 files changed, 591 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java index 33c8341..b5b84b8 100644 --- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java +++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java @@ -63,4 +63,22 @@ public class JsfModuleConfig implements DeltaSpikeConfig { return false; } + + /** + * Per default converters get wrapped to restore them properly during a postback (significant without overhead). + * @return true if converters should be handled as std. CDI beans, false otherwise + */ + public boolean isContainerManagedConvertersEnabled() + { + return true; + } + + /** + * Per default validators get wrapped to restore them properly during a postback (significant without overhead). + * @return true if validators should be handled as std. CDI beans, false otherwise + */ + public boolean isContainerManagedValidatorsEnabled() + { + return true; + } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractBeanStorage.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractBeanStorage.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractBeanStorage.java new file mode 100644 index 0000000..4f1c79d --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractBeanStorage.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.annotation.PreDestroy; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +abstract class AbstractBeanStorage +{ + private static final Logger LOG = Logger.getLogger(AbstractBeanStorage.class.getName()); + + private List dependentBeanEntries = new ArrayList(); + + void add(DependentBeanEntry dependentBeanEntry) + { + this.dependentBeanEntries.add(dependentBeanEntry); + } + + @PreDestroy + public void cleanup() + { + for (DependentBeanEntry beanEntry : this.dependentBeanEntries) + { + try + { + beanEntry.getBean().destroy(beanEntry.getInstance(), beanEntry.getCreationalContext()); + } + catch (RuntimeException e) + { + LOG.log(Level.SEVERE, e.getMessage(), e); + } + } + this.dependentBeanEntries.clear(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java new file mode 100644 index 0000000..33e1258 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.faces.FacesWrapper; +import javax.faces.component.PartialStateHolder; +import javax.faces.component.StateHolder; +import javax.faces.context.FacesContext; + +//no backward compatibility for full state-saving +abstract class AbstractContextualReferenceWrapper implements PartialStateHolder, FacesWrapper +{ + private T wrapped; + + protected AbstractContextualReferenceWrapper(T wrapped) + { + this.wrapped = wrapped; + } + + @Override + public void markInitialState() + { + if (this.wrapped instanceof PartialStateHolder) + { + ((PartialStateHolder) this.wrapped).markInitialState(); + } + } + + @Override + public void clearInitialState() + { + if (this.wrapped instanceof PartialStateHolder) + { + ((PartialStateHolder) this.wrapped).clearInitialState(); + } + } + + @Override + public boolean initialStateMarked() + { + return this.wrapped instanceof PartialStateHolder && ((PartialStateHolder) this.wrapped).initialStateMarked(); + } + + @Override + public Object saveState(FacesContext context) + { + if (this.wrapped instanceof StateHolder) + { + return ((StateHolder)wrapped).saveState(context); + } + + return null; + } + + @Override + public void restoreState(FacesContext context, Object state) + { + if (this.wrapped instanceof StateHolder) + { + ((StateHolder)this.wrapped).restoreState(context, state); + } + } + + @Override + public boolean isTransient() + { + return this.wrapped instanceof StateHolder && ((StateHolder) this.wrapped).isTransient(); + } + + @Override + public void setTransient(boolean newTransientValue) + { + if (this.wrapped instanceof StateHolder) + { + ((StateHolder) this.wrapped).setTransient(newTransientValue); + } + } + + @Override + public T getWrapped() + { + return this.wrapped; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java new file mode 100644 index 0000000..0a362df --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; + +public class ConverterWrapper extends AbstractContextualReferenceWrapper implements Converter +{ + public ConverterWrapper(Converter wrapped) + { + super(wrapped); + } + + @Override + public Object getAsObject(FacesContext facesContext, UIComponent component, String value) throws ConverterException + { + return getWrapped().getAsObject(facesContext, component, value); + } + + @Override + public String getAsString(FacesContext facesContext, UIComponent component, Object value) throws ConverterException + { + return getWrapped().getAsString(facesContext, component, value); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/DependentBeanEntry.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/DependentBeanEntry.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/DependentBeanEntry.java new file mode 100644 index 0000000..5a23e30 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/DependentBeanEntry.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Bean; +import java.io.Serializable; + +class DependentBeanEntry implements Serializable +{ + private static final long serialVersionUID = 7148484695430831322L; + + private final T instance; + private final Bean bean; + private final CreationalContext creationalContext; + + DependentBeanEntry(T instance, Bean bean, CreationalContext creationalContext) + { + this.instance = instance; + this.bean = bean; + this.creationalContext = creationalContext; + } + + T getInstance() + { + return instance; + } + + Bean getBean() + { + return bean; + } + + CreationalContext getCreationalContext() + { + return creationalContext; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java new file mode 100644 index 0000000..531a675 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import org.apache.deltaspike.jsf.api.config.JsfModuleConfig; + +import javax.faces.FacesException; +import javax.faces.application.Application; +import javax.faces.application.ApplicationWrapper; +import javax.faces.convert.Converter; +import javax.faces.validator.Validator; + +public class InjectionAwareApplicationWrapper extends ApplicationWrapper +{ + private final Application wrapped; + private final boolean containerManagedConvertersEnabled; + private final boolean containerManagedValidatorsEnabled; + + public InjectionAwareApplicationWrapper(Application wrapped, JsfModuleConfig jsfModuleConfig) + { + this.wrapped = wrapped; + this.containerManagedConvertersEnabled = jsfModuleConfig.isContainerManagedConvertersEnabled(); + this.containerManagedValidatorsEnabled = jsfModuleConfig.isContainerManagedValidatorsEnabled(); + } + + @Override + public Converter createConverter(Class targetClass) + { + return managedOrDefaultConverter(this.wrapped.createConverter(targetClass)); + } + + @Override + public Converter createConverter(String converterId) + { + return managedOrDefaultConverter(this.wrapped.createConverter(converterId)); + } + + private Converter managedOrDefaultConverter(Converter defaultResult) + { + if (!this.containerManagedConvertersEnabled) + { + return defaultResult; + } + if (defaultResult == null) + { + return null; + } + + Converter result = ManagedArtifactResolver.resolveManagedConverter(defaultResult.getClass()); + + if (result == null) + { + return defaultResult; + } + else + { + return new ConverterWrapper(result); + } + } + + @Override + public Validator createValidator(String validatorId) throws FacesException + { + return managedOrDefaultValidator(this.wrapped.createValidator(validatorId)); + } + + private Validator managedOrDefaultValidator(Validator defaultResult) + { + if (!this.containerManagedValidatorsEnabled) + { + return defaultResult; + } + if (defaultResult == null) + { + return null; + } + + Validator result = ManagedArtifactResolver.resolveManagedValidator(defaultResult.getClass()); + + if (result == null) + { + return defaultResult; + } + else + { + return new ValidatorWrapper(result); + } + } + + @Override + public Application getWrapped() + { + return wrapped; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ManagedArtifactResolver.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ManagedArtifactResolver.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ManagedArtifactResolver.java new file mode 100644 index 0000000..417b724 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ManagedArtifactResolver.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import org.apache.deltaspike.core.api.provider.BeanManagerProvider; +import org.apache.deltaspike.core.api.provider.BeanProvider; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.Typed; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeanManager; +import javax.faces.convert.Converter; +import javax.faces.validator.Validator; +import java.io.Serializable; +import java.util.Set; + +@Typed() +public abstract class ManagedArtifactResolver +{ + public static final String JAVAX_FACES_CONVERT_PACKAGE_NAME = "javax.faces.convert"; + public static final String JAVAX_FACES_VALIDATOR_PACKAGE_NAME = "javax.faces.validator"; + + /** + * Constructor which prevents the instantiation of this class + */ + private ManagedArtifactResolver() + { + } + + public static Converter resolveManagedConverter(Class converterClass) + { + if (JAVAX_FACES_CONVERT_PACKAGE_NAME.equals(converterClass.getPackage().getName())) + { + return null; + } + + return getContextualReference(BeanManagerProvider.getInstance().getBeanManager(), converterClass); + } + + public static Validator resolveManagedValidator(Class validatorClass) + { + if (JAVAX_FACES_VALIDATOR_PACKAGE_NAME.equals(validatorClass.getPackage().getName())) + { + return null; + } + + return getContextualReference(BeanManagerProvider.getInstance().getBeanManager(), validatorClass); + } + + private static T getContextualReference(BeanManager beanManager, Class type) + { + Set> beans = beanManager.getBeans(type); + + if (beans == null || beans.isEmpty()) + { + return null; + } + + Bean bean = beanManager.resolve(beans); + + CreationalContext creationalContext = beanManager.createCreationalContext(bean); + + @SuppressWarnings({ "unchecked", "UnnecessaryLocalVariable" }) + T result = (T) beanManager.getReference(bean, type, creationalContext); + + if (bean.getScope().equals(Dependent.class)) + { + AbstractBeanStorage beanStorage; + + if (Serializable.class.isAssignableFrom(bean.getBeanClass())) + { + beanStorage = BeanProvider.getContextualReference(ViewDependentBeanStorage.class); + } + else + { + beanStorage = BeanProvider.getContextualReference(RequestDependentBeanStorage.class); + } + + //noinspection unchecked + beanStorage.add(new DependentBeanEntry(result, bean, creationalContext)); + } + + return result; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/RequestDependentBeanStorage.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/RequestDependentBeanStorage.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/RequestDependentBeanStorage.java new file mode 100644 index 0000000..93a7299 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/RequestDependentBeanStorage.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +public class RequestDependentBeanStorage extends AbstractBeanStorage +{ +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java new file mode 100644 index 0000000..f306f8e --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +public class ValidatorWrapper extends AbstractContextualReferenceWrapper implements Validator +{ + public ValidatorWrapper(Validator wrapped) + { + super(wrapped); + } + + @Override + public void validate(FacesContext facesContext, UIComponent component, Object value) throws ValidatorException + { + getWrapped().validate(facesContext, component, value); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ViewDependentBeanStorage.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ViewDependentBeanStorage.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ViewDependentBeanStorage.java new file mode 100644 index 0000000..1a62f40 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ViewDependentBeanStorage.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.jsf.impl.injection; + +import javax.faces.bean.ViewScoped; +import java.io.Serializable; + +@ViewScoped +public class ViewDependentBeanStorage extends AbstractBeanStorage implements Serializable +{ + private static final long serialVersionUID = 4500399024267716556L; +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b209f589/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java index 2c995a5..5b11d38 100644 --- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java @@ -21,9 +21,12 @@ package org.apache.deltaspike.jsf.impl.listener.request; import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver; import org.apache.deltaspike.core.api.provider.BeanProvider; import org.apache.deltaspike.core.util.ClassDeactivationUtils; +import org.apache.deltaspike.jsf.api.config.JsfModuleConfig; import org.apache.deltaspike.jsf.impl.config.view.DefaultErrorViewAwareExceptionHandlerWrapper; +import org.apache.deltaspike.jsf.impl.injection.InjectionAwareApplicationWrapper; import org.apache.deltaspike.jsf.impl.message.FacesMessageEntry; +import javax.faces.application.Application; import javax.faces.application.FacesMessage; import javax.faces.context.ExceptionHandler; import javax.faces.context.ExternalContext; @@ -43,6 +46,8 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper private ExternalContext wrappedExternalContext; + private JsfModuleConfig jsfModuleConfig; + DeltaSpikeFacesContextWrapper(FacesContext wrappedFacesContext) { this.wrappedFacesContext = wrappedFacesContext; @@ -151,6 +156,17 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper } @Override + public Application getApplication() + { + if (this.jsfModuleConfig == null) + { + this.jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class); + } + + return new InjectionAwareApplicationWrapper(this.wrappedFacesContext.getApplication(), this.jsfModuleConfig); + } + + @Override public FacesContext getWrapped() { return this.wrappedFacesContext;