You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/02/19 02:46:53 UTC

svn commit: r628958 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib: components/formfragment_ref_1.png components/formfragment_ref_2.png internal/FormSupportAdapter.java mixins/TriggerFragment.java

Author: hlship
Date: Mon Feb 18 17:46:51 2008
New Revision: 628958

URL: http://svn.apache.org/viewvc?rev=628958&view=rev
Log:
TAPESTRY-1650: Add the FormFragment component and TriggerFragment mixin

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_1.png   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_2.png   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/internal/FormSupportAdapter.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_1.png
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_1.png?rev=628958&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_1.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_2.png
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_2.png?rev=628958&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/formfragment_ref_2.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/internal/FormSupportAdapter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/internal/FormSupportAdapter.java?rev=628958&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/internal/FormSupportAdapter.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/internal/FormSupportAdapter.java Mon Feb 18 17:46:51 2008
@@ -0,0 +1,68 @@
+// Copyright 2008 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.tapestry.corelib.internal;
+
+import org.apache.tapestry.ComponentAction;
+import org.apache.tapestry.Field;
+import org.apache.tapestry.services.FormSupport;
+
+/**
+ * An implementation of {@link org.apache.tapestry.services.FormSupport} that delegates all behavior
+ * to another instance of FormSupport. This allows some of the behavior to be overridden easily.
+ */
+public class FormSupportAdapter implements FormSupport
+{
+    private final FormSupport _delegate;
+
+    public FormSupportAdapter(FormSupport delegate)
+    {
+        _delegate = delegate;
+    }
+
+    public String allocateControlName(String id)
+    {
+        return _delegate.allocateControlName(id);
+    }
+
+    public <T> void store(T component, ComponentAction<T> action)
+    {
+        _delegate.store(component, action);
+    }
+
+    public <T> void storeAndExecute(T component, ComponentAction<T> action)
+    {
+        _delegate.storeAndExecute(component, action);
+    }
+
+    public void defer(Runnable command)
+    {
+        _delegate.defer(command);
+    }
+
+    public void setEncodingType(String encodingType)
+    {
+        _delegate.setEncodingType(encodingType);
+    }
+
+    public void addValidation(Field field, String validationName, String message, Object constraint)
+    {
+        _delegate.addValidation(field, validationName, message, constraint);
+    }
+
+    public String getClientId()
+    {
+        return _delegate.getClientId();
+    }
+}

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java?rev=628958&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java Mon Feb 18 17:46:51 2008
@@ -0,0 +1,67 @@
+// Copyright 2008 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.tapestry.corelib.mixins;
+
+import org.apache.tapestry.ClientElement;
+import org.apache.tapestry.Field;
+import org.apache.tapestry.PageRenderSupport;
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.InjectContainer;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.services.Heartbeat;
+
+/**
+ * A mixin that can be applied to a Checkbox component that will link
+ * the checkbox and a FormFragment, making the Checkbox control the client-side visibility
+ * of the FormFragment.
+ *
+ * @see org.apache.tapestry.corelib.components.Checkbox
+ * @see org.apache.tapestry.corelib.components.FormFragment
+ */
+public class TriggerFragment
+{
+    @InjectContainer
+    private Field _container;
+
+    /**
+     * The {@link org.apache.tapestry.corelib.components.FormFragment} instance to make dynamically visible or hidden.
+     */
+    @Parameter(required = true, defaultPrefix = "component")
+    private ClientElement _fragment;
+
+    @Environmental
+    private PageRenderSupport _pageRenderSupport;
+
+    @Environmental
+    private Heartbeat _heartbeat;
+
+    void beginRender()
+    {
+        Runnable r = new Runnable()
+        {
+            public void run()
+            {
+                _pageRenderSupport.addScript("Tapestry.linkCheckboxToFormFragment('%s', '%s');",
+                                             _container.getClientId(),
+                                             _fragment.getClientId());
+            }
+        };
+
+        // Defer generating the script to ensure that the FormFragment has rendered
+        // and generated its client id.
+
+        _heartbeat.defer(r);
+    }
+}