Author: hlship
Date: Tue Jan 22 09:38:14 2008
New Revision: 614269
URL: http://svn.apache.org/viewvc?rev=614269&view=rev
Log:
TAPESTRY-1647: Need to be able to render elements before and after form labels
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/OverrideValidationDecorator.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/ChattyValidationDecorator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/OverrideValidationDecorator.java
Removed:
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/StubValidationDecorator.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BaseValidationDecorator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ValidationDecorator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/UploadTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BaseValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BaseValidationDecorator.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BaseValidationDecorator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BaseValidationDecorator.java
Tue Jan 22 09:38:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 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.
@@ -17,11 +17,19 @@
import org.apache.tapestry.dom.Element;
/**
- * Base implementation of [EMAIL PROTECTED] ValidationDecorator} that does
nothing. Subclasses may override
- * specific methods, knowing that all other methods do nothing at all.
+ * Base implementation of [EMAIL PROTECTED] ValidationDecorator} that does
nothing. Subclasses may override specific methods,
+ * knowing that all other methods do nothing at all.
*/
-public abstract class BaseValidationDecorator implements ValidationDecorator
+public class BaseValidationDecorator implements ValidationDecorator
{
+
+ public void beforeLabel(Field field)
+ {
+ }
+
+ public void afterLabel(Field field)
+ {
+ }
public void afterField(Field field)
{
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ValidationDecorator.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ValidationDecorator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ValidationDecorator.java
Tue Jan 22 09:38:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 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.
@@ -17,32 +17,51 @@
import org.apache.tapestry.dom.Element;
/**
- * An object responsible for performing decorations around fields and field
labels. The decorator is
- * notified at intervals by the fields and labels.
+ * An object responsible for performing decorations around fields and field
labels. The decorator is notified at
+ * intervals by the fields and labels.
+ * <p/>
+ * In most western languages (written left to right) the label will render
before the field, so the properties of the
+ * Field may not be set yet (or may reflect a previous looping's rendering).
It may be necessary to [EMAIL PROTECTED]
+ * org.apache.tapestry.services.Heartbeat#defer(Runnable)} defer any
rendering} until after the Label and the Field have
+ * both had their change to initialize and render.
*/
public interface ValidationDecorator
{
/**
- * Invoked after the label has rendered its tag, but before it has
rendered content inside the
- * tag, to allow the decorator to write additional attributes.
+ * Invoked by a [EMAIL PROTECTED]
org.apache.tapestry.corelib.components.Label} before rendering itself.
+ *
+ * @param field for this label
+ */
+ void beforeLabel(Field field);
+
+ /**
+ * Invoked after the label has rendered its tag, but before it has
rendered content inside the tag, to allow the
+ * decorator to write additional attributes.
*
* @param field the field corresponding to the label
* @param labelElement the element for this label
*/
void insideLabel(Field field, Element labelElement);
+
+ /**
+ * Invoked by [EMAIL PROTECTED]
org.apache.tapestry.corelib.components.Label} after rendering itself.
+ *
+ * @param field
+ */
+ void afterLabel(Field field);
+
/**
- * Renders immediately before the field itself. The field will typically
render a single
- * element, though a complex field may render multiple elements or even
some JavaScript.
+ * Renders immediately before the field itself. The field will typically
render a single element, though a complex
+ * field may render multiple elements or even some JavaScript.
*
* @param field
*/
void beforeField(Field field);
/**
- * Invoked at a point where the decorator may write additional attributes
into the field.
- * Generally speaking, you will want to
- * [EMAIL PROTECTED]
ComponentResources#renderInformalParameters(MarkupWriter) render informal
parameters}
+ * Invoked at a point where the decorator may write additional attributes
into the field. Generally speaking, you
+ * will want to [EMAIL PROTECTED]
ComponentResources#renderInformalParameters(MarkupWriter) render informal
parameters}
* <strong>before</strong> invoking this method.
*
* @param field
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
Tue Jan 22 09:38:14 2008
@@ -30,8 +30,8 @@
public class Label
{
/**
- * The for parameter is used to identify the [EMAIL PROTECTED] Field}
linked to this label (it is named
- * this way because it results in the for attribute of the label element).
+ * The for parameter is used to identify the [EMAIL PROTECTED] Field}
linked to this label (it is named this way because it
+ * results in the for attribute of the label element).
*/
@Parameter(name = "for", required = true, defaultPrefix = "component")
private Field _field;
@@ -50,18 +50,12 @@
{
final Field field = _field;
+ _decorator.beforeLabel(field);
+
final Element element = writer.element("label");
_resources.renderInformalParameters(writer);
- // Uh oh! Referencing a private field (that happens to get
instrumented up the wazoo) from
- // a inner class causes a java.lang.Verify error (Unable to pop
operand off an empty stack).
- // Perhaps this is a Javassist error? Shouldn't the inner class be
going through a synthetic
- // accessor method of some kind? Resolved by assigning to a local
variable and referencing
- // that. Layers on layers, oh my!
-
- final ValidationDecorator decorator = _decorator;
-
// Since we don't know if the field has rendered yet, we need to defer
writing the for
// attribute until we know the field has rendered (and set its
clientId property). That's
// exactly what Heartbeat is for.
@@ -74,7 +68,7 @@
element.forceAttributes("for", fieldId, "id", fieldId +
":label");
- decorator.insideLabel(field, element);
+ _decorator.insideLabel(field, element);
}
};
@@ -95,5 +89,7 @@
writer.write(_field.getLabel());
writer.end(); // label
+
+ _decorator.afterLabel(_field);
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
Tue Jan 22 09:38:14 2008
@@ -90,7 +90,6 @@
private void addErrorClassToCurrentElement()
{
-
_markupWriter.getElement().addClassName(TapestryConstants.ERROR_CLASS);
}
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/OverrideValidationDecorator.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/OverrideValidationDecorator.tml?rev=614269&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/OverrideValidationDecorator.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/OverrideValidationDecorator.tml
Tue Jan 22 09:38:14 2008
@@ -0,0 +1,13 @@
+<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>Override Validation Decorator</h1>
+
+ <p>
+ Demonstrates how to override the default Validation Decorator for a
page or a component (this is often
+ done inside a layout component). In addition, used to verify that the
Label component
+ invokes Validation Decorator methods at the correct time.
+ </p>
+
+ <t:beaneditform t:id="form" object="this"/>
+
+</html>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Tue Jan 22 09:38:14 2008
@@ -1435,4 +1435,16 @@
assertText(locator, "0");
}
+
+ /**
+ * TAPESTRY-1647
+ */
+ @Test
+ public void label_invokes_validation_decorator_at_correct_time()
+ {
+ start("Override Validation Decorator");
+
+ assertSourcePresent(
+ "[Before label for Value]<label for=\"value\"
id=\"value:label\">Value</label>[After label for Value][Before field Value]");
+ }
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/ChattyValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/ChattyValidationDecorator.java?rev=614269&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/ChattyValidationDecorator.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/ChattyValidationDecorator.java
Tue Jan 22 09:38:14 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.integration.app1;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.ValidationDecorator;
+import org.apache.tapestry.dom.Element;
+
+public class ChattyValidationDecorator implements ValidationDecorator
+{
+ private final MarkupWriter _writer;
+
+ private final ValidationDecorator _delegate;
+
+ public ChattyValidationDecorator(MarkupWriter writer, ValidationDecorator
delegate)
+ {
+ _writer = writer;
+ _delegate = delegate;
+ }
+
+ public void beforeLabel(Field field)
+ {
+ _writer.writef("[Before label for %s]", field.getLabel());
+ }
+
+ public void afterLabel(Field field)
+ {
+ _writer.writef("[After label for %s]", field.getLabel());
+ }
+
+ public void beforeField(Field field)
+ {
+ _writer.writef("[Before field %s]", field.getLabel());
+
+ _delegate.beforeField(field);
+ }
+
+ public void insideField(Field field)
+ {
+ _delegate.insideField(field);
+ }
+
+ public void afterField(Field field)
+ {
+ _delegate.afterField(field);
+
+ _writer.writef("[After field %s]", field.getLabel());
+ }
+
+ public void insideLabel(Field field, Element labelElement)
+ {
+ _delegate.insideLabel(field, labelElement);
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/OverrideValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/OverrideValidationDecorator.java?rev=614269&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/OverrideValidationDecorator.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/OverrideValidationDecorator.java
Tue Jan 22 09:38:14 2008
@@ -0,0 +1,52 @@
+// 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.integration.app1.pages;
+
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.ValidationDecorator;
+import org.apache.tapestry.integration.app1.ChattyValidationDecorator;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.services.Environment;
+
+public class OverrideValidationDecorator
+{
+ private String _value;
+
+ @Inject
+ private Environment _environment;
+
+ void beginRender(MarkupWriter writer)
+ {
+ ValidationDecorator existing =
_environment.peekRequired(ValidationDecorator.class);
+
+ _environment.push(ValidationDecorator.class, new
ChattyValidationDecorator(writer, existing));
+ }
+
+ void afterRender()
+ {
+ _environment.pop(ValidationDecorator.class);
+ }
+
+ public String getValue()
+ {
+ return _value;
+ }
+
+ public void setValue(String value)
+ {
+ _value = value;
+ }
+}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
Tue Jan 22 09:38:14 2008
@@ -201,7 +201,10 @@
new Item("MagicValueEncoder", "Magic ValueEncoder Demo",
"Automatic creation of ValueEncoder using the
TypeCoercer"),
- new Item("NullStrategyDemo", "Null Field Strategy Demo", "use of
the nulls parameter of TextField"));
+ new Item("NullStrategyDemo", "Null Field Strategy Demo", "use of
the nulls parameter of TextField"),
+
+ new Item("OverrideValidationDecorator", "Override Validation
Decorator",
+ "override the default validation decorator"));
static
{
Modified:
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/UploadTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/UploadTest.java?rev=614269&r1=614268&r2=614269&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/UploadTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/apache/tapestry/upload/components/UploadTest.java
Tue Jan 22 09:38:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 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.
@@ -48,7 +48,7 @@
Upload component = new Upload(null, null, null, null, resources, null);
- component.injectDecorator(new StubValidationDecorator());
+ component.injectDecorator(new BaseValidationDecorator());
component.injectFormSupport(formSupport);
component.beginRender(writer);