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 2008/09/23 12:36:40 UTC
svn commit: r698126 - in /myfaces/extensions/validator/branches/jsf_1.1:
core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/
core/src/main/java/org/apache/myfaces/extensions/validator/util/
validation-modules/property...
Author: gpetracek
Date: Tue Sep 23 03:36:39 2008
New Revision: 698126
URL: http://svn.apache.org/viewvc?rev=698126&view=rev
Log:
support for multiple DefaultComponentInitializer implementations
Added:
myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
Removed:
myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/DefaultMyFacesComponentInitializer.java
Modified:
myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
Modified: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java?rev=698126&r1=698125&r2=698126&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java (original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/component/DefaultComponentInitializer.java Tue Sep 23 03:36:39 2008
@@ -24,6 +24,8 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
/**
* @author Gerhard Petracek
@@ -32,19 +34,22 @@
@UsageInformation(UsageCategory.INTERNAL)
public class DefaultComponentInitializer implements ComponentInitializer
{
- private static ComponentInitializer componentInitializer;
+ private static List<ComponentInitializer> componentInitializers = new ArrayList<ComponentInitializer>();
public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String, Object> metaData)
{
- if(componentInitializer != null)
+ for(ComponentInitializer componentInitializer : componentInitializers)
{
componentInitializer.configureComponent(facesContext, uiComponent, metaData);
}
}
@UsageInformation(UsageCategory.INTERNAL)
- public static void setComponentInitializer(ComponentInitializer componentInitializer)
+ public static void addComponentInitializer(ComponentInitializer componentInitializer)
{
- DefaultComponentInitializer.componentInitializer = componentInitializer;
+ synchronized (DefaultComponentInitializer.class)
+ {
+ componentInitializers.add(componentInitializer);
+ }
}
}
Modified: myfaces/extensions/validator/branches/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/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=698126&r1=698125&r2=698126&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java (original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java Tue Sep 23 03:36:39 2008
@@ -21,6 +21,8 @@
import org.apache.myfaces.extensions.validator.core.InformationProviderBean;
import org.apache.myfaces.extensions.validator.core.ProcessedInformationEntry;
import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.component.DefaultComponentInitializer;
import org.apache.myfaces.extensions.validator.internal.ToDo;
import org.apache.myfaces.extensions.validator.internal.Priority;
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -201,4 +203,9 @@
.put(VALUE_BINDING_CONVERTED_VALUE_MAPPING_KEY,
new HashMap<String, ProcessedInformationEntry>());
}
+
+ public static void addComponentInitializer(ComponentInitializer componentInitializer)
+ {
+ DefaultComponentInitializer.addComponentInitializer(componentInitializer);
+ }
}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java?rev=698126&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java Tue Sep 23 03:36:39 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.myfaces.extensions.validator;
+
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class HtmlCoreComponentsComponentInitializer implements ComponentInitializer
+{
+ public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String, Object> metaData)
+ {
+ configureRequiredAttribute(facesContext, uiComponent, metaData);
+ configureMaxLengthAttribute(facesContext, uiComponent, metaData);
+ }
+
+ protected void configureRequiredAttribute(FacesContext facesContext,
+ UIComponent uiComponent,
+ Map<String, Object> metaData)
+ {
+ if(metaData.containsKey(MetaDataKeys.REQUIRED))
+ {
+ if((Boolean)metaData.get(MetaDataKeys.REQUIRED) && Boolean.TRUE.equals(isComponentRequired(uiComponent)))
+ {
+ ((EditableValueHolder)uiComponent).setRequired(true);
+ }
+ }
+ }
+
+ /**
+ * if there is no special attribute at the component which should overrule
+ * the annotated property return true!
+ *
+ * @param uiComponent component which implements the EditableValueHolder interface
+ * @return false to overrule the annotated property e.g. if component is readonly
+ */
+ protected Boolean isComponentRequired(UIComponent uiComponent)
+ {
+ if(uiComponent instanceof HtmlInputText)
+ {
+ HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
+ return !(htmlInputText.isReadonly() || htmlInputText.isDisabled());
+ }
+
+ return null;
+ }
+
+ protected void configureMaxLengthAttribute(FacesContext facesContext,
+ UIComponent uiComponent,
+ Map<String, Object> metaData)
+ {
+ if(metaData.containsKey(MetaDataKeys.MAX_LENGTH))
+ {
+ int maxLength = (Integer)metaData.get(MetaDataKeys.MAX_LENGTH);
+
+ if(uiComponent instanceof HtmlInputText)
+ {
+ HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
+ htmlInputText.setMaxlength(maxLength);
+ }
+ }
+ }
+}
Modified: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java?rev=698126&r1=698125&r2=698126&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java (original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/InitPropertyValidationModulePhaseListener.java Tue Sep 23 03:36:39 2008
@@ -20,7 +20,6 @@
import org.apache.myfaces.extensions.validator.baseval.WebXmlParameter;
import org.apache.myfaces.extensions.validator.core.AbstractStartupConfigListener;
-import org.apache.myfaces.extensions.validator.core.initializer.component.DefaultComponentInitializer;
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import org.apache.myfaces.extensions.validator.internal.ToDo;
import org.apache.myfaces.extensions.validator.internal.Priority;
@@ -55,6 +54,7 @@
@ToDo(value = Priority.MEDIUM, description = "web.xml parameter to deactivate it")
private void initDefaultComponentInitializerName()
{
- DefaultComponentInitializer.setComponentInitializer(new DefaultMyFacesComponentInitializer());
+ ExtValUtils.addComponentInitializer(new HtmlCoreComponentsComponentInitializer());
+ ExtValUtils.addComponentInitializer(new TrinidadComponentInitializer());
}
}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java?rev=698126&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/TrinidadComponentInitializer.java Tue Sep 23 03:36:39 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.myfaces.extensions.validator;
+
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class TrinidadComponentInitializer extends HtmlCoreComponentsComponentInitializer
+{
+ private static final String TRINIDAD_CORE_INPUT_TEXT
+ = "org.apache.myfaces.trinidad.component.core.input.CoreInputText";
+ private static final String TRINIDAD_CORE_INPUT_DATE
+ = "org.apache.myfaces.trinidad.component.core.input.CoreInputDate";
+ @Override
+ protected Boolean isComponentRequired(UIComponent uiComponent)
+ {
+ if(processComponent(uiComponent))
+ {
+ return !((Boolean) ReflectionUtils
+ .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(), "isReadOnly") ||
+ (Boolean) ReflectionUtils
+ .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(), "isDisabled"));
+ }
+ //ToDo impl. the rest
+ return null;
+ }
+
+ @Override
+ protected void configureMaxLengthAttribute(FacesContext facesContext,
+ UIComponent uiComponent,
+ Map<String, Object> metaData)
+ {
+ if(metaData.containsKey(MetaDataKeys.MAX_LENGTH))
+ {
+ int maxLength = (Integer)metaData.get(MetaDataKeys.MAX_LENGTH);
+
+ if(processComponent(uiComponent))
+ {
+ ReflectionUtils
+ .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(), "setMaximumLength",
+ new Object[] {maxLength}, new Class[] {int.class});
+ }
+ }
+ }
+
+ private boolean processComponent(UIComponent uiComponent)
+ {
+ return TRINIDAD_CORE_INPUT_TEXT.equals(uiComponent.getClass().getName()) ||
+ TRINIDAD_CORE_INPUT_DATE.equals(uiComponent.getClass().getName());
+ }
+}