Author: hlship
Date: Tue Jan 2 12:08:19 2007
New Revision: 491920
URL: http://svn.apache.org/viewvc?view=rev&rev=491920
Log:
Support default binding methods, which allow default bindings to be computed
(useful for TextField's value and label parameters, for example).
Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/DefaultParameterBindingMethodComponent.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.properties
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BindingSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/BindingSource.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/SimpleForm.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.html
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -32,7 +32,11 @@
import org.apache.tapestry.corelib.mixins.RenderDisabled;
import org.apache.tapestry.corelib.mixins.RenderInformals;
import org.apache.tapestry.internal.TapestryUtils;
+import org.apache.tapestry.internal.bindings.LiteralBinding;
import org.apache.tapestry.internal.services.FormParameterLookup;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.services.Binding;
+import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.FormSupport;
import org.apache.tapestry.services.PageRenderSupport;
@@ -134,6 +138,31 @@
@Inject("service:tapestry.internal.FormParameterLookup")
private FormParameterLookup _paramLookup;
+ Binding defaultLabel()
+ {
+ Messages containerMessages =
_resources.getContainer().getComponentResources()
+ .getMessages();
+
+ String componentId = _resources.getId();
+
+ String key = componentId + "-label";
+
+ String label = containerMessages.contains(key) ?
containerMessages.get(key) : TapestryUtils
+ .toUserPresentable(componentId);
+
+ // Bypassing the BindingSource for this ...
+
+ return new LiteralBinding("default label", label, null);
+ }
+
+ public final String getLabel()
+ {
+ if (_label != null)
+ return _label;
+
+ return TapestryUtils.toUserPresentable(_resources.getId());
+ }
+
@SetupRender
final void setup()
{
@@ -175,6 +204,19 @@
processSubmission(_paramLookup, _elementName);
}
+ @Inject("infrastructure:BindingSource")
+ private BindingSource _bindingSource;
+
+ /** Used by subclasses to create a default binding to a property of the
container. */
+ protected final Binding createDefaultParameterBinding(String parameterName)
+ {
+ String componentId = _resources.getId();
+
+ ComponentResources container =
_resources.getContainer().getComponentResources();
+
+ return _bindingSource.newBinding("default " + parameterName,
container, componentId);
+ }
+
/**
* Method implemented by subclasses to actually do the work of processing
the submission of the
* form. The element's elementName property will already have been set.
This method is only
@@ -189,14 +231,6 @@
* the name of the element (used to find the correct parameter
in the request)
*/
protected abstract void processSubmission(FormParameterLookup paramLookup,
String elementName);
-
- public final String getLabel()
- {
- if (_label != null)
- return _label;
-
- return TapestryUtils.toUserPresentable(_resources.getId());
- }
/**
* A field validator that does nothing. This is used as the default for
subclasses' validate
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -14,6 +14,7 @@
package org.apache.tapestry.corelib.base;
+import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.FieldValidator;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.Translator;
@@ -21,8 +22,10 @@
import org.apache.tapestry.ValidationTracker;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.internal.services.FormParameterLookup;
+import org.apache.tapestry.services.Binding;
/** Abstract class for a variety of components that render some variation of a
text field. */
public abstract class AbstractTextField extends AbstractField
@@ -38,6 +41,17 @@
@Environmental
private ValidationTracker _tracker;
+
+ @Inject
+ private ComponentResources _resources;
+
+ /**
+ * The default value is a property of the container whose name matches the
component's id.
+ */
+ Binding defaultValue()
+ {
+ return createDefaultParameterBinding("value");
+ }
@BeginRender
final void begin(MarkupWriter writer)
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -20,6 +20,7 @@
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.corelib.base.AbstractField;
import org.apache.tapestry.internal.services.FormParameterLookup;
+import org.apache.tapestry.services.Binding;
/** A Checkbox coponent is simply a <input type="checkbox">. */
public class Checkbox extends AbstractField
@@ -27,6 +28,11 @@
@Parameter(required = true)
private boolean _value;
+
+ Binding defaultValue()
+ {
+ return createDefaultParameterBinding("value");
+ }
@BeginRender
void begin(MarkupWriter writer)
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BindingSourceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BindingSourceImpl.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BindingSourceImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/BindingSourceImpl.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -20,6 +20,7 @@
import java.util.Map;
import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.internal.InternalConstants;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.internal.util.TapestryException;
import org.apache.tapestry.services.Binding;
@@ -33,6 +34,17 @@
public BindingSourceImpl(Map<String, BindingFactory> factories)
{
_factories = factories;
+ }
+
+ public Binding newBinding(String description, ComponentResources
container, String expression)
+ {
+ return newBinding(
+ description,
+ container,
+ container,
+ InternalConstants.PROP_BINDING_PREFIX,
+ expression,
+ null);
}
public Binding newBinding(String description, ComponentResources container,
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
Tue Jan 2 12:08:19 2007
@@ -18,13 +18,14 @@
import java.util.List;
import org.apache.tapestry.annotations.Parameter;
-import org.apache.tapestry.internal.InternalConstants;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.util.BodyBuilder;
import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.services.Binding;
import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ComponentClassTransformWorker;
+import org.apache.tapestry.services.MethodFilter;
import org.apache.tapestry.services.MethodSignature;
import org.apache.tapestry.services.TransformConstants;
import org.apache.tapestry.services.TransformUtils;
@@ -47,9 +48,7 @@
List<String> fieldNames =
transformation.findFieldsWithAnnotation(Parameter.class);
for (String name : fieldNames)
- {
convertFieldIntoParameter(name, transformation, model);
- }
}
private void convertFieldIntoParameter(String name, ClassTransformation
transformation,
@@ -118,25 +117,12 @@
BodyBuilder builder = new BodyBuilder();
builder.begin();
- if (InternalUtils.isNonBlank(defaultBinding))
- {
- builder.addln("if (! %s.isBound(\"%s\"))", resourcesFieldName,
parameterName);
-
- String bindingFactoryFieldName = transformation.addInjectedField(
- BindingSource.class,
- "bindingSource",
- _bindingSource);
-
- builder
- .addln(
- " %s.addParameter(\"%s\", %s.newBinding(\"default
%2$s\", %1$s, %1$s, \"%s\", \"%s\", null));",
- resourcesFieldName,
- parameterName,
- bindingFactoryFieldName,
- InternalConstants.PROP_BINDING_PREFIX,
- defaultBinding);
-
- }
+ addDefaultBindingSetup(
+ parameterName,
+ defaultBinding,
+ resourcesFieldName,
+ transformation,
+ builder);
builder.addln(
"%s = %s.isInvariant(\"%s\");",
@@ -173,6 +159,60 @@
}
return invariantFieldName;
+ }
+
+ private void addDefaultBindingSetup(String parameterName, String
defaultBinding,
+ String resourcesFieldName, ClassTransformation transformation,
BodyBuilder builder)
+ {
+ if (InternalUtils.isNonBlank(defaultBinding))
+ {
+ builder.addln("if (! %s.isBound(\"%s\"))", resourcesFieldName,
parameterName);
+
+ String bindingFactoryFieldName = transformation.addInjectedField(
+ BindingSource.class,
+ "bindingSource",
+ _bindingSource);
+
+ builder
+ .addln(
+ " %s.addParameter(\"%s\", %s.newBinding(\"default
%2$s\", %1$s, \"%s\"));",
+ resourcesFieldName,
+ parameterName,
+ bindingFactoryFieldName,
+ defaultBinding);
+
+ return;
+
+ }
+
+ // If no default binding expression provided in the annotation, then
look for a default
+ // binding method to provide the binding.
+
+ final String methodName = "default" +
InternalUtils.capitalize(parameterName);
+
+ MethodFilter filter = new MethodFilter()
+ {
+ public boolean accept(MethodSignature signature)
+ {
+ return signature.getParameterTypes().length == 0
+ && signature.getMethodName().equals(methodName)
+ &&
signature.getReturnType().equals(Binding.class.getName());
+ }
+ };
+
+ // This will match exactly 0 or 1 methods, and if it matches, we know
the name
+ // of the method.
+
+ if (!transformation.findMethods(filter).isEmpty())
+ {
+ builder.addln("if (! %s.isBound(\"%s\"))", resourcesFieldName,
parameterName);
+
+ builder.addln(
+ " %s.addParameter(\"%s\", %s());",
+ resourcesFieldName,
+ parameterName,
+ methodName);
+ }
}
private void addWriterMethod(String fieldName, String cachedFieldName,
boolean cache,
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
Tue Jan 2 12:08:19 2007
@@ -50,7 +50,6 @@
import org.apache.tapestry.model.EmbeddedComponentModel;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.RenderQueue;
-import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ComponentClassResolver;
import org.apache.tapestry.services.Infrastructure;
import org.apache.tapestry.services.Request;
@@ -268,11 +267,6 @@
protected final EmbeddedComponentModel newEmbeddedComponentModel()
{
return newMock(EmbeddedComponentModel.class);
- }
-
- protected final BindingSource newBindingSource()
- {
- return newMock(BindingSource.class);
}
protected final PageElementFactory newPageElementFactory()
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/BindingSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/BindingSource.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/BindingSource.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/BindingSource.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -49,4 +49,22 @@
*/
Binding newBinding(String description, ComponentResources container,
ComponentResources component, String defaultPrefix, String
expression, Location location);
+
+ /**
+ * A simpler version of
+ * [EMAIL PROTECTED] #newBinding(String, ComponentResources,
ComponentResources, String, String, Location)}
+ * that defaults the values for several parameters. This is used in most
cases. The default
+ * binding prefix will be "prop". Most often, this is used to create a new
default binding.
+ *
+ * @param description
+ * description of the binding, such as "parameter foo"
+ * @param container
+ * typically, the parent of the component. This value will be
used as the container
+ * <em>and</em> the component, so whatever type of expression
is evaluated, will be
+ * evaulated in terms of this component
+ * @param expression
+ * the binding
+ * @return a binding
+ */
+ Binding newBinding(String description, ComponentResources container,
String expression);
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -53,6 +53,7 @@
import org.apache.tapestry.services.AssetFactory;
import org.apache.tapestry.services.Binding;
import org.apache.tapestry.services.BindingFactory;
+import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ClasspathAssetAliasManager;
import org.apache.tapestry.services.ComponentClassResolver;
@@ -579,5 +580,10 @@
protected final Messages newMessages()
{
return newMock(Messages.class);
+ }
+
+ protected final BindingSource newBindingSource()
+ {
+ return newMock(BindingSource.class);
}
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
Tue Jan 2 12:08:19 2007
@@ -248,6 +248,46 @@
As elsewhere, you may use a prefix on the value. A common prefix to use is
the "message:" prefix, to access a localized message.
+Computed Parameter Binding Defaults
+
+ In <rare> cases, you may want to compute the binding to be used as a
parameter default. In this case, you will provide
+ a <default binding method>, a method that takes no parameters and returns a
+ {{{../apidocs/org/apache/tapestry/Binding.html}Binding}} instance. The
method name is "default" plus the capitalized name
+ of the parameter.
+
+ Using this approach, the previous example may be rewritten as:
+
++----+
+ @Parameter
+ private String _message;
+
+ @Parameter(required=true)
+ private int _maxLength;
+
+ @Inject
+ private ComponentResources _resources;
+
+ @Inject("infrastructure:BindingSource")
+ private BindingSource _bindingSource;
+
+ Binding defaultValue()
+ {
+ return _bindingSource.newBinding("default value", _resources,
"defaultMessage");
+ }
+
+ public String getDefaultMessage()
+ {
+ return String.format("Maximum field length is %d.", _maxLength);
+ }
++---+
+
+ Obviously, this is a lot more work than simply specifying a default value as
part of the Parameter annotation. In the few
+ real cases where this is approach is used, the default binding method will
usually deduce a proper binding, typically in terms of
+ the component's id. For example, the TextField component will deduce a
value parameter that binds to a property of its container with
+ the same name.
+
+ A default binding method will <only> be invoked if the Parameter annotation
does not provide a default value.
+
Unbound Parameters
If a parameter is not bound (and is optional), then the value may be read or
<updated> at any time.
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Tue Jan 2 12:08:19 2007
@@ -297,10 +297,10 @@
clickAndWait("link=SimpleForm");
- assertText("//label[1]", "Disable");
+ assertText("//label[1]", "Disabled");
assertText("//label[2]", "Email");
assertText("//label[3]", "Incident Message");
- assertText("//label[4]", "Urgent");
+ assertText("//label[4]", "Urgent Processing Requested");
assertValue("email", "");
assertValue("message", "");
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/SimpleForm.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/SimpleForm.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/SimpleForm.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/SimpleForm.java
Tue Jan 2 12:08:19 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/DefaultParameterBindingMethodComponent.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/DefaultParameterBindingMethodComponent.java?view=auto&rev=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/DefaultParameterBindingMethodComponent.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/DefaultParameterBindingMethodComponent.java
Tue Jan 2 12:08:19 2007
@@ -0,0 +1,36 @@
+// Copyright 2007 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.internal.services;
+
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.services.Binding;
+
[EMAIL PROTECTED]
+public class DefaultParameterBindingMethodComponent
+{
+ @Parameter
+ private String _value;
+
+ public String getValue()
+ {
+ return _value;
+ }
+
+ Binding defaultValue()
+ {
+ return ParameterWorkerTest._binding;
+ }
+}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
Tue Jan 2 12:08:19 2007
@@ -21,7 +21,6 @@
import org.apache.commons.logging.Log;
import org.apache.tapestry.internal.InternalComponentResources;
-import org.apache.tapestry.internal.InternalConstants;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
import org.apache.tapestry.ioc.internal.services.PropertyAccessImpl;
import org.apache.tapestry.ioc.services.PropertyAccess;
@@ -43,10 +42,16 @@
private PropertyAccess _access = new PropertyAccessImpl();
+ /**
+ * Accessed by DefaultParameerBindingMethodComponent.
+ */
+ public static Binding _binding;
+
@AfterClass
public void cleanup()
{
_access = null;
+ _binding = null;
}
@Test
@@ -471,14 +476,8 @@
{
train_isBound(resources, "value", false);
- expect(
- source.newBinding(
- "default value",
- resources,
- resources,
- InternalConstants.PROP_BINDING_PREFIX,
- "literal:greeting",
- null)).andReturn(binding);
+ expect(source.newBinding("default value", resources,
"literal:greeting"))
+ .andReturn(binding);
resources.addParameter("value", binding);
@@ -491,6 +490,51 @@
resources,
newLog(),
DefaultParameterComponent.class.getName(),
+ model,
+ source,
+ phaseTwoTraining);
+
+ train_isLoaded(resources, true);
+ train_isBound(resources, "value", true);
+ train_readParameter(resources, "value", String.class, boundValue);
+
+ replay();
+
+ assertEquals(_access.get(component, "value"), boundValue);
+
+ verify();
+ }
+
+ @Test
+ public void default_binding_method() throws Exception
+ {
+ BindingSource source = newBindingSource();
+ final InternalComponentResources resources =
newInternalComponentResources();
+ _binding = newBinding();
+ String boundValue = "yowza!";
+
+ MutableComponentModel model = newMutableComponentModel();
+
+ model.addParameter("value", false);
+
+ Runnable phaseTwoTraining = new Runnable()
+ {
+ public void run()
+ {
+ train_isBound(resources, "value", false);
+
+ // How can this happen? Only if the generated code invokes
defaultValue().
+
+ resources.addParameter("value", _binding);
+
+ train_isInvariant(resources, "value", true);
+ };
+ };
+
+ Component component = setupForIntegrationTest(
+ resources,
+ newLog(),
+ DefaultParameterBindingMethodComponent.class.getName(),
model,
source,
phaseTwoTraining);
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.html?view=diff&rev=491920&r1=491919&r2=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.html
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.html
Tue Jan 2 12:08:19 2007
@@ -4,8 +4,8 @@
<p> This is the <em>very early</em> start to Tapestry 5 form support. </p>
<t:comp type="Form">
- <t:comp type="Checkbox" id="disable" value="disabled"/>
- <t:comp type="Label" field="component:disable"/>
+ <t:comp type="Checkbox" id="disabled"/>
+ <t:comp type="Label" field="component:disabled"/>
<hr/>
Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.properties?view=auto&rev=491920
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.properties
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/SimpleForm.properties
Tue Jan 2 12:08:19 2007
@@ -0,0 +1 @@
+urgent-label=Urgent Processing Requested
\ No newline at end of file