You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/11/13 13:45:02 UTC
svn commit: r835830 - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator:
core/ core/renderkit/ util/
Author: gpetracek
Date: Fri Nov 13 12:45:02 2009
New Revision: 835830
URL: http://svn.apache.org/viewvc?rev=835830&view=rev
Log:
EXTVAL-58 in combination with EXTVAL-38 (+ in combination with jsf 2.0)
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/AbstractRenderKitWrapperFactory.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRenderKitFactory.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java Fri Nov 13 12:45:02 2009
@@ -29,7 +29,6 @@
public enum CustomInformation
{
BASE_PACKAGE,
- EXTVAL_CONTEXT,
COMPONENT_META_DATA_EXTRACTOR,
VALIDATION_PARAMETER_EXTRACTOR,
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java Fri Nov 13 12:45:02 2009
@@ -37,7 +37,6 @@
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.util.ClassUtils;
-import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -57,6 +56,10 @@
private static ExtValContext extValContext;
+ //don't try to resolve it dynamically e.g. via InformationProviderBean - there's a mojarra issue
+ private static final String CUSTOM_EXTVAL_CONTEXT_CLASS_NAME =
+ ExtValContext.class.getName().replace(".core.", ".custom.");
+
private ViolationSeverityInterpreter violationSeverityInterpreter;
private FactoryFinder factoryFinder = DefaultFactoryFinder.getInstance();
private Map<String, RendererInterceptor> rendererInterceptors = new HashMap<String, RendererInterceptor>();
@@ -74,7 +77,7 @@
private ExtValContextInternals contextHelper;
private ExtValContextInvocationOrderAwareInternals invocationOrderAwareContextHelper;
- private ExtValContext()
+ protected ExtValContext()
{
this.contextHelper = new ExtValContextInternals();
this.invocationOrderAwareContextHelper = new ExtValContextInvocationOrderAwareInternals(this.contextHelper);
@@ -86,24 +89,21 @@
{
extValContext = new ExtValContext();
- if(ExtValUtils.isApplicationInitialized())
- {
- Object customExtValContext = ExtValUtils.getELHelper().getBean(
- extValContext.getInformationProviderBean().get(CustomInformation.EXTVAL_CONTEXT));
-
- if (customExtValContext instanceof ExtValContext)
- {
- extValContext = (ExtValContext) customExtValContext;
- }
- }
- else
- {
- //TODO try to use web.xml context-param
- }
+ tryToCreateCustomExtValContext();
}
return extValContext;
}
+ private static void tryToCreateCustomExtValContext()
+ {
+ Object customExtValContext = ClassUtils.tryToInstantiateClassForName(CUSTOM_EXTVAL_CONTEXT_CLASS_NAME);
+
+ if (customExtValContext instanceof ExtValContext)
+ {
+ extValContext = (ExtValContext) customExtValContext;
+ }
+ }
+
public void setViolationSeverityInterpreter(ViolationSeverityInterpreter violationSeverityInterpreter)
{
setViolationSeverityInterpreter(violationSeverityInterpreter, true);
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java Fri Nov 13 12:45:02 2009
@@ -75,7 +75,6 @@
}
customizableInfos.put(CustomInformation.BASE_PACKAGE, basePackage);
- customizableInfos.put(CustomInformation.EXTVAL_CONTEXT, "customExtValContext");
customizableInfos.put(CustomInformation.COMPONENT_META_DATA_EXTRACTOR,
"ComponentMetaDataExtractor");
@@ -149,9 +148,6 @@
case BASE_PACKAGE:
return value;
- case EXTVAL_CONTEXT:
- return value;
-
/*
* postfix used by the SimpleAnnotationToValidationStrategyNameMapper
* the SimpleAnnotationToValidationStrategyNameMapper is for custom strategies only
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/AbstractRenderKitWrapperFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/AbstractRenderKitWrapperFactory.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/AbstractRenderKitWrapperFactory.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/AbstractRenderKitWrapperFactory.java Fri Nov 13 12:45:02 2009
@@ -25,6 +25,7 @@
import org.apache.commons.logging.LogFactory;
import javax.faces.render.RenderKit;
+import javax.faces.context.FacesContext;
/**
* Base for all RenderKitWrapperFactories to force a specific behaviour
@@ -102,4 +103,18 @@
}
protected abstract RenderKit createWrapper(RenderKit renderKit);
+
+ /**
+ * simple test for early config in case of mojarra (incl. the combination with trinidad).
+ * use a custom extval context impl. (see EXTVAL-58) to optimize this check for the target runtime.
+ * this check works for all current implementations since the jsf internals are autom. ready during a request
+ * @return true if the jsf impl. is initialized and it's possible to use it as expected
+ */
+ protected boolean isApplicationInitialized()
+ {
+ return FacesContext.getCurrentInstance().getClass().getName().startsWith("org.apache.myfaces") ||
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap() != null &&
+ !FacesContext.getCurrentInstance().getExternalContext().getRequestMap().isEmpty();
+
+ }
}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRenderKitFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRenderKitFactory.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRenderKitFactory.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/renderkit/ExtValRenderKitFactory.java Fri Nov 13 12:45:02 2009
@@ -22,7 +22,8 @@
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.core.ExtValContext;
import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
-import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+import org.apache.myfaces.extensions.validator.ExtValInformation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -42,7 +43,7 @@
{
protected final Log logger = LogFactory.getLog(getClass());
private RenderKitFactory wrapped;
- private DefaultRenderKitWrapperFactory defaultRenderKitWrapperFactory = new DefaultRenderKitWrapperFactory();
+ private AbstractRenderKitWrapperFactory defaultRenderKitWrapperFactory;
public ExtValRenderKitFactory(RenderKitFactory renderKitFactory)
{
@@ -69,8 +70,10 @@
return null;
}
+ tryToInitDefaultRenderKitWrapperFactory();
+
//test early config in case of mojarra
- if(!ExtValUtils.isApplicationInitialized())
+ if(!this.defaultRenderKitWrapperFactory.isApplicationInitialized())
{
return this.defaultRenderKitWrapperFactory.createWrapper(renderKit);
}
@@ -78,6 +81,27 @@
return tryToCreateWrapperWithWrapperFactory(renderKit);
}
+ private synchronized void tryToInitDefaultRenderKitWrapperFactory()
+ {
+ if(this.defaultRenderKitWrapperFactory == null)
+ {
+ //workaround for mojarra to allow a custom factory during the early config phase
+ //just create the factory with the given name
+ //+it should extend your custom implementation which you register as usual
+ Object customFactory = ClassUtils.tryToInstantiateClassForName(
+ ExtValInformation.EXTENSIONS_VALIDATOR_BASE_PACKAGE_NAME + ".custom.RenderKitWrapperFactory");
+
+ if(customFactory instanceof AbstractRenderKitWrapperFactory)
+ {
+ this.defaultRenderKitWrapperFactory = (AbstractRenderKitWrapperFactory)customFactory;
+ }
+ else
+ {
+ this.defaultRenderKitWrapperFactory = new DefaultRenderKitWrapperFactory();
+ }
+ }
+ }
+
private RenderKit tryToCreateWrapperWithWrapperFactory(RenderKit renderKit)
{
AbstractRenderKitWrapperFactory wrapperFactory = ExtValContext.getContext().getFactoryFinder()
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=835830&r1=835829&r2=835830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java Fri Nov 13 12:45:02 2009
@@ -894,19 +894,4 @@
}
return targetComponent;
}
-
- public static boolean isApplicationInitialized()
- {
- try
- {
- //simple test for early config in case of mojarra
- FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().isEmpty();
- }
- catch (Throwable e)
- {
- return false;
- }
-
- return true;
- }
}