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 2011/03/03 20:19:05 UTC
svn commit: r1076735 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base:
AbstractField.java AbstractTextField.java
Author: hlship
Date: Thu Mar 3 19:19:04 2011
New Revision: 1076735
URL: http://svn.apache.org/viewvc?rev=1076735&view=rev
Log:
TAP5-1459: Remove AbstractField.createDefaultParameterBinding() and AbstractTextField.defaultValue()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java?rev=1076735&r1=1076734&r2=1076735&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java Thu Mar 3 19:19:04 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 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
+// 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,
@@ -58,11 +58,10 @@ public abstract class AbstractField impl
@Environmental
private ValidationDecorator decorator;
-
+
@Inject
private Environment environment;
-
static class Setup implements ComponentAction<AbstractField>, Serializable
{
private static final long serialVersionUID = 2690270808212097020L;
@@ -153,7 +152,8 @@ public abstract class AbstractField impl
// exceptions, including a form that renders inside a loop, or a form inside a component
// that is used multiple times.
- if (formSupport == null) throw new RuntimeException(InternalMessages.formFieldOutsideForm(getLabel()));
+ if (formSupport == null)
+ throw new RuntimeException(InternalMessages.formFieldOutsideForm(getLabel()));
assignedClientId = jsSupport.allocateClientId(id);
String controlName = formSupport.allocateControlName(id);
@@ -187,26 +187,17 @@ public abstract class AbstractField impl
private void processSubmission()
{
- if (!disabled) processSubmission(controlName);
- }
-
- /**
- * Used by subclasses to create a default binding to a property of the container matching the component id.
- *
- * @return a binding to the property, or null if the container does not have a corresponding property
- * @deprecated Use {@link ComponentDefaultProvider#defaultBinding(String, ComponentResources)} instead
- */
- protected final Binding createDefaultParameterBinding(String parameterName)
- {
- return defaultProvider.defaultBinding(parameterName, resources);
+ if (!disabled)
+ processSubmission(controlName);
}
/**
* 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 invoked if the field is <strong>not {@link
- * #isDisabled() disabled}</strong>.
- *
- * @param elementName the name of the element (used to find the correct parameter in the request)
+ * elementName property will already have been set. This method is only invoked if the field is <strong>not
+ * {@link #isDisabled() disabled}</strong>.
+ *
+ * @param elementName
+ * the name of the element (used to find the correct parameter in the request)
*/
protected abstract void processSubmission(String elementName);
@@ -254,28 +245,30 @@ public abstract class AbstractField impl
{
return false;
}
-
+
protected void putPropertyNameIntoBeanValidationContext(String parameterName)
{
- String propertyName = ((InternalComponentResources)resources).getPropertyName(parameterName);
-
+ String propertyName = ((InternalComponentResources) resources).getPropertyName(parameterName);
+
BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
-
- if(beanValidationContext == null) return;
- //If field is inside BeanEditForm, then property is already set
- if(beanValidationContext.getCurrentProperty()==null)
+ if (beanValidationContext == null)
+ return;
+
+ // If field is inside BeanEditForm, then property is already set
+ if (beanValidationContext.getCurrentProperty() == null)
{
- beanValidationContext.setCurrentProperty(propertyName);
+ beanValidationContext.setCurrentProperty(propertyName);
}
}
-
+
protected void removePropertyNameFromBeanValidationContext()
- {
- BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
-
- if(beanValidationContext == null) return;
-
- beanValidationContext.setCurrentProperty(null);
+ {
+ BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
+
+ if (beanValidationContext == null)
+ return;
+
+ beanValidationContext.setCurrentProperty(null);
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java?rev=1076735&r1=1076734&r2=1076735&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java Thu Mar 3 19:19:04 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 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
+// 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,
@@ -31,7 +31,7 @@ import java.util.Locale;
* Abstract class for a variety of components that render some variation of a text field. Most of the hooks for user
* input validation are in this class.
* <p/>
- * In particular, all subclasses support the "toclient" and "parseclient" events. These two events allow the normal
+ * In particular, all subclasses support the "toclient" and "parseclient" events. These two events allow the normal
* {@link Translator} (specified by the translate parameter, but often automatically derived by Tapestry) to be
* augmented.
* <p/>
@@ -40,10 +40,11 @@ import java.util.Locale;
* handler method is t he current value of the value parameter.
* <p/>
* Likewise, on a form submit, the "parseclient" event handler method will be passed the string provided by the client,
- * and may provide a non-null value as the parsed value. Returning null allows the normal translator to operate. The
+ * and may provide a non-null value as the parsed value. Returning null allows the normal translator to operate. The
* event handler may also throw {@link org.apache.tapestry5.ValidationException}.
*/
-@Events({ EventConstants.TO_CLIENT, EventConstants.VALIDATE, EventConstants.PARSE_CLIENT })
+@Events(
+{ EventConstants.TO_CLIENT, EventConstants.VALIDATE, EventConstants.PARSE_CLIENT })
public abstract class AbstractTextField extends AbstractField
{
/**
@@ -52,7 +53,7 @@ public abstract class AbstractTextField
* container matching the component's id. If no such property exists, then you will see a runtime exception due to
* the unbound value parameter.
*/
- @Parameter(required = true, principal = true)
+ @Parameter(required = true, principal = true, autoconnect = true)
private Object value;
/**
@@ -71,9 +72,9 @@ public abstract class AbstractTextField
private FieldValidator<Object> validate;
/**
- * Provider of annotations used for some defaults. Annotation are usually provided in terms of the value parameter
+ * Provider of annotations used for some defaults. Annotation are usually provided in terms of the value parameter
* (i.e., from the getter and/or setter bound to the value parameter).
- *
+ *
* @see org.apache.tapestry5.beaneditor.Width
*/
@Parameter
@@ -81,7 +82,7 @@ public abstract class AbstractTextField
/**
* Defines how nulls on the server side, or sent from the client side, are treated. The selected strategy may
- * replace the nulls with some other value. The default strategy leaves nulls alone. Another built-in strategy,
+ * replace the nulls with some other value. The default strategy leaves nulls alone. Another built-in strategy,
* zero, replaces nulls with the value 0.
*/
@Parameter(defaultPrefix = BindingConstants.NULLFIELDSTRATEGY, value = "default")
@@ -110,8 +111,9 @@ public abstract class AbstractTextField
private ComponentDefaultProvider defaultProvider;
/**
- * Computes a default value for the "translate" parameter using {@link org.apache.tapestry5.services.ComponentDefaultProvider#defaultTranslator(String,
- * org.apache.tapestry5.ComponentResources)}.
+ * Computes a default value for the "translate" parameter using
+ * {@link org.apache.tapestry5.services.ComponentDefaultProvider#defaultTranslator(String, org.apache.tapestry5.ComponentResources)}
+ * .
*/
final Binding defaultTranslate()
{
@@ -130,26 +132,16 @@ public abstract class AbstractTextField
}
/**
- * Computes a default value for the "validate" parameter using {@link org.apache.tapestry5.services.FieldValidatorDefaultSource}.
+ * Computes a default value for the "validate" parameter using
+ * {@link org.apache.tapestry5.services.FieldValidatorDefaultSource}.
*/
final Binding defaultValidate()
{
return defaultProvider.defaultValidatorBinding("value", resources);
}
- /**
- * The default value is a property of the container whose name matches the component's id. May return null if the
- * container does not have a matching property.
- *
- * @deprecated Likely to be removed in the future, use {@link org.apache.tapestry5.annotations.Parameter#autoconnect()}
- * instead
- */
- final Binding defaultValue()
- {
- return createDefaultParameterBinding("value");
- }
-
- @SuppressWarnings({ "unchecked" })
+ @SuppressWarnings(
+ { "unchecked" })
@BeginRender
void begin(MarkupWriter writer)
{
@@ -168,12 +160,12 @@ public abstract class AbstractTextField
}
writeFieldTag(writer, value);
-
+
putPropertyNameIntoBeanValidationContext("value");
translate.render(writer);
validate.render(writer);
-
+
removePropertyNameFromBeanValidationContext();
resources.renderInformalParameters(writer);
@@ -188,13 +180,16 @@ public abstract class AbstractTextField
* <p/>
* Generally, the subclass will invoke {@link MarkupWriter#element(String, Object[])}, and will be responsible for
* including an {@link AfterRender} phase method to invoke {@link MarkupWriter#end()}.
- *
- * @param writer markup write to send output to
- * @param value the value (either obtained and translated from the value parameter, or obtained from the tracker)
+ *
+ * @param writer
+ * markup write to send output to
+ * @param value
+ * the value (either obtained and translated from the value parameter, or obtained from the tracker)
*/
protected abstract void writeFieldTag(MarkupWriter writer, String value);
- @SuppressWarnings({ "unchecked" })
+ @SuppressWarnings(
+ { "unchecked" })
@Override
protected void processSubmission(String elementName)
{
@@ -205,7 +200,7 @@ public abstract class AbstractTextField
try
{
Object translated = fieldValidationSupport.parseClient(rawValue, resources, translate, nulls);
-
+
putPropertyNameIntoBeanValidationContext("value");
fieldValidationSupport.validate(translated, resources, validate);
@@ -220,14 +215,13 @@ public abstract class AbstractTextField
{
tracker.recordError(this, ex.getMessage());
}
-
+
removePropertyNameFromBeanValidationContext();
}
-
/**
- * Should blank input be ignored (after validation)? This will be true for {@link
- * org.apache.tapestry5.corelib.components.PasswordField}.
+ * Should blank input be ignored (after validation)? This will be true for
+ * {@link org.apache.tapestry5.corelib.components.PasswordField}.
*/
protected boolean ignoreBlankInput()
{
@@ -243,14 +237,15 @@ public abstract class AbstractTextField
/**
* Looks for a {@link org.apache.tapestry5.beaneditor.Width} annotation and, if present, returns its value as a
* string.
- *
+ *
* @return the indicated width, or null if the annotation is not present
*/
protected final String getWidth()
{
Width width = annotationProvider.getAnnotation(Width.class);
- if (width == null) return null;
+ if (width == null)
+ return null;
return Integer.toString(width.value());
}