You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2014/06/03 18:21:19 UTC

[2/4] git commit: Some minor refactorings to more pleasant service names

Some minor refactorings to more pleasant service names

Also, only complain about a pre-selected client id if not ensuring uniqueness


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/c8a7eddb
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c8a7eddb
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c8a7eddb

Branch: refs/heads/master
Commit: c8a7eddbacdf718dfd82d3fc14f692f09fe6f7d2
Parents: 193d022
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jun 3 09:15:52 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jun 3 09:21:33 2014 -0700

----------------------------------------------------------------------
 .../tapestry5/corelib/base/AbstractField.java   | 27 ++++++-----
 .../tapestry5/corelib/components/Form.java      |  8 ++--
 .../services/FormControlNameManager.java        | 39 ++++++++++++++++
 .../services/FormControlNameManagerImpl.java    | 45 +++++++++++++++++++
 .../services/PreSelectedFormNamesService.java   | 39 ----------------
 .../PreSelectedFormNamesServiceImpl.java        | 47 --------------------
 .../tapestry5/modules/InternalModule.java       |  4 +-
 7 files changed, 105 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
index beb4d1d..871499e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
@@ -18,7 +18,7 @@ import org.apache.tapestry5.corelib.mixins.DiscardBody;
 import org.apache.tapestry5.corelib.mixins.RenderInformals;
 import org.apache.tapestry5.internal.BeanValidationContext;
 import org.apache.tapestry5.internal.InternalComponentResources;
-import org.apache.tapestry5.internal.services.PreSelectedFormNamesService;
+import org.apache.tapestry5.internal.services.FormControlNameManager;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
@@ -169,7 +169,7 @@ public abstract class AbstractField implements Field
     protected FieldValidationSupport fieldValidationSupport;
 
     @Inject
-    private PreSelectedFormNamesService preSelectedFormNamesService;
+    private FormControlNameManager formControlNameManager;
 
     final String defaultLabel()
     {
@@ -207,18 +207,25 @@ public abstract class AbstractField implements Field
             return javaScriptSupport.allocateClientId(resources);
         }
 
-        if (preSelectedFormNamesService.isPreselected(clientId))
-        {
-            throw new TapestryException(String.format(
-                    "The value '%s' for parameter clientId is not allowed as it causes a naming conflict in the client-side DOM. " +
-                            "Select a name not in the list: %s.",
-                    clientId,
-                    InternalUtils.joinSorted(preSelectedFormNamesService.getNames())), this, null);
-        }
 
         if (ensureClientIdUnique)
         {
             return javaScriptSupport.allocateClientId(clientId);
+        } else
+        {
+            // See https://issues.apache.org/jira/browse/TAP5-1632
+            // Basically, on the client, there can be a convenience lookup inside a HTMLFormElement
+            // by id OR name; so an id of "submit" (for example) will mask the HTMLFormElement.submit()
+            // function.
+
+            if (formControlNameManager.isPreselected(clientId))
+            {
+                throw new TapestryException(String.format(
+                        "The value '%s' for parameter clientId is not allowed as it causes a naming conflict in the client-side DOM. " +
+                                "Select an id not in the list: %s.",
+                        clientId,
+                        InternalUtils.joinSorted(formControlNameManager.getPreselectedNames())), this, null);
+            }
         }
 
         return clientId;

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
index bb8d6a0..9f2452d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
@@ -1,5 +1,3 @@
-// Copyright 2006-2014 The Apache Software Foundation
-//
 // Licensed 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
@@ -22,8 +20,8 @@ import org.apache.tapestry5.corelib.internal.FormSupportImpl;
 import org.apache.tapestry5.corelib.internal.InternalFormSupport;
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.internal.*;
+import org.apache.tapestry5.internal.services.FormControlNameManager;
 import org.apache.tapestry5.internal.services.HeartbeatImpl;
-import org.apache.tapestry5.internal.services.PreSelectedFormNamesService;
 import org.apache.tapestry5.internal.util.AutofocusValidationDecorator;
 import org.apache.tapestry5.ioc.Location;
 import org.apache.tapestry5.ioc.Messages;
@@ -223,7 +221,7 @@ public class Form implements ClientElement, FormValidationControl
     private ComponentSource source;
 
     @Inject
-    private PreSelectedFormNamesService preSelectedFormNamesService;
+    private FormControlNameManager formControlNameManager;
 
 
     /**
@@ -741,7 +739,7 @@ public class Form implements ClientElement, FormValidationControl
 
     private void preallocateNames(IdAllocator idAllocator)
     {
-        for (String name : preSelectedFormNamesService.getNames())
+        for (String name : formControlNameManager.getPreselectedNames())
         {
             idAllocator.allocateId(name);
             // See https://issues.apache.org/jira/browse/TAP5-1632

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManager.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManager.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManager.java
new file mode 100644
index 0000000..7179197
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManager.java
@@ -0,0 +1,39 @@
+// Licensed 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.tapestry5.internal.services;
+package org.apache.tapestry5.internal.services;
+
+import java.util.Set;
+
+import org.apache.tapestry5.internal.InternalSymbols;
+
+/**
+ * Service providing methods related to names that shouldn't be used as HTML elements client ids.
+ * 
+ * @see InternalSymbols#PRE_SELECTED_FORM_NAMES
+ */
+public interface FormControlNameManager
+{
+    /**
+     * Returns the set of pre-selected form names (ones that shouldn't be used as HTML elements
+     * client ids).
+     * @return a {@link Set} of {@link String}s.
+     */
+    Set<String> getPreselectedNames();
+    
+    /**
+     * Tells whether a given name is pre-selected.
+     * @param string
+     * @return
+     */
+    boolean isPreselected(String name);
+    
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManagerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManagerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManagerImpl.java
new file mode 100644
index 0000000..5e586c2
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FormControlNameManagerImpl.java
@@ -0,0 +1,45 @@
+// Licensed 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.tapestry5.internal.services;
+package org.apache.tapestry5.internal.services;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.tapestry5.internal.InternalSymbols;
+import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+
+public class FormControlNameManagerImpl implements FormControlNameManager
+{
+    
+    final private Set<String> names;
+
+    public FormControlNameManagerImpl(
+            @Symbol(InternalSymbols.PRE_SELECTED_FORM_NAMES) String preselectedFormNames)
+    {
+        this.names = Collections.unmodifiableSet(CollectionFactory.<String,String>newSet(TapestryInternalUtils.splitAtCommas(preselectedFormNames)));
+    }
+
+    @Override
+    public Set<String> getPreselectedNames()
+    {
+        return names;
+    }
+
+    @Override
+    public boolean isPreselected(String name)
+    {
+        return names.contains(name.toLowerCase());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesService.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesService.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesService.java
deleted file mode 100644
index 379c53b..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesService.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed 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.tapestry5.internal.services;
-package org.apache.tapestry5.internal.services;
-
-import java.util.Set;
-
-import org.apache.tapestry5.internal.InternalSymbols;
-
-/**
- * Service providing methods related to names that shouldn't be used as HTML elements client ids.
- * 
- * @see InternalSymbols#PRE_SELECTED_FORM_NAMES
- */
-public interface PreSelectedFormNamesService
-{
-    /**
-     * Returns the set of pre-selected form names (ones that shouldn't be used as HTML elements
-     * client ids.
-     * @return a {@link Set} of {@link String}s.
-     */
-    Set<String> getNames();
-    
-    /**
-     * Tells whether a given name is pre-selected.
-     * @param string
-     * @return
-     */
-    boolean isPreselected(String name);
-    
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesServiceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesServiceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesServiceImpl.java
deleted file mode 100644
index a6c801b..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PreSelectedFormNamesServiceImpl.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2014 The Apache Software Foundation
-//
-// Licensed 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.tapestry5.internal.services;
-package org.apache.tapestry5.internal.services;
-
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.tapestry5.internal.InternalSymbols;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-
-public class PreSelectedFormNamesServiceImpl implements PreSelectedFormNamesService
-{
-    
-    final private Set<String> names;
-
-    public PreSelectedFormNamesServiceImpl(    
-            @Symbol(InternalSymbols.PRE_SELECTED_FORM_NAMES) String preselectedFormNames)
-    {
-        this.names = Collections.unmodifiableSet(CollectionFactory.<String,String>newSet(TapestryInternalUtils.splitAtCommas(preselectedFormNames)));
-    }
-
-    @Override
-    public Set<String> getNames()
-    {
-        return names;
-    }
-
-    @Override
-    public boolean isPreselected(String name)
-    {
-        return names.contains(name.toLowerCase());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8a7eddb/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java
index 32473ac..6d7f967 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java
@@ -1,5 +1,3 @@
-// Copyright 2008-2013 The Apache Software Foundation
-//
 // Licensed 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
@@ -72,7 +70,7 @@ public class InternalModule
         binder.bind(PageLoader.class, PageLoaderImpl.class).preventReloading();
         binder.bind(UnknownActivationContextHandler.class, UnknownActivationContextHandlerImpl.class);
         binder.bind(ReloadHelper.class, ReloadHelperImpl.class);
-        binder.bind(PreSelectedFormNamesService.class, PreSelectedFormNamesServiceImpl.class);
+        binder.bind(FormControlNameManager.class, FormControlNameManagerImpl.class);
 
     }