You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by fr...@apache.org on 2007/02/04 15:40:42 UTC
svn commit: r503415 [1/3] - in /tapestry/tapestry5/tapestry-core:
branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/
branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/
branches/kt-20070204-IDE-support/src/...
Author: freemant
Date: Sun Feb 4 06:40:39 2007
New Revision: 503415
URL: http://svn.apache.org/viewvc?view=rev&rev=503415
Log:
Initial commit for the branch.
Added:
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java (with props)
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java (with props)
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/components/
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java (with props)
tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/AnnotationValidatorGenerator.java
- copied, changed from r503165, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldValidatorGenerator.java
- copied, changed from r503165, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidatorGenerator.java
- copied, changed from r503165, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/SelectTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TextFieldTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/AnnotationValidatorGeneratorTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/CompoundValidatorGeneratorTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImplTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FormPersistWorkerTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpClassTransformation.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpComponentResources.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpField.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpFieldComponent.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpValidator.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/NoOpBindingSource.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForSelect.html (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForTextField.html (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForTextField.properties (with props)
Removed:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/ValidateBindingFactory.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorSource.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/ValidateBindingFactoryTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/pom.xml
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumSelectModel.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumValueEncoder.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionGroupModel.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionModel.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SelectModel.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueEncoder.java
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/BeanEditForm.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/Label.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.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/OptionGroupModelImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionModelImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/SelectModelImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/TapestryUtils.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/LongTranslator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/OptionGroupModelImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/OptionModelImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryUtilsTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForForm.html
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForSubmit.html
Added: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java (added)
+++ tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,83 @@
+// 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;
+
+import org.apache.tapestry.internal.bindings.LiteralBinding;
+import org.apache.tapestry.internal.services.NoOpComponentResources;
+import org.apache.tapestry.runtime.ComponentResourcesAware;
+import org.apache.tapestry.services.BindingSource;
+import org.apache.tapestry.services.NoOpBindingSource;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class BindingExprValueConduitTest extends Assert
+{
+ public static class MyComponent implements BindingSourceProvider, ComponentResourcesAware
+ {
+ private ComponentResources _resources;
+
+ private BindingSource _bindingSource;
+
+ public MyComponent(ComponentResources resources, BindingSource bindingSource)
+ {
+ _resources = resources;
+ _bindingSource = bindingSource;
+ }
+
+ public ComponentResources getComponentResources()
+ {
+ return _resources;
+ }
+
+ public BindingSource getBindingSource()
+ {
+ return _bindingSource;
+ }
+
+ }
+
+ @Test
+ public void test()
+ {
+ final ComponentResources containerResources = new NoOpComponentResources();
+ NoOpComponentResources componentResources = new NoOpComponentResources()
+ {
+
+ @Override
+ public ComponentResources getContainerResources()
+ {
+ return containerResources;
+ }
+
+ };
+ BindingSource bindingSource = new NoOpBindingSource()
+ {
+
+ @Override
+ public Binding newBinding(String description, ComponentResources container,
+ String expression)
+ {
+ assertSame(container, containerResources);
+ return new LiteralBinding("", "[" + expression + "]", null);
+ }
+
+ };
+ MyComponent component = new MyComponent(componentResources, bindingSource);
+ BindingExprValueConduit conduit = new BindingExprValueConduit("foo");
+ assertEquals(conduit.get(component), "[foo]");
+
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/BindingExprValueConduitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java (added)
+++ tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,64 @@
+// 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.corelib.base;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class RestorePropertiesActionTest extends Assert
+{
+ public static class Foo
+ {
+ int v1;
+
+ String _v2;
+
+ public void setV1(int v1)
+ {
+ this.v1 = v1;
+ }
+
+ public void setV2(String v2)
+ {
+ this._v2 = v2;
+ }
+
+ public int getV1()
+ {
+ return v1;
+ }
+
+ public String getV2()
+ {
+ return _v2;
+ }
+
+ }
+
+ @Test
+ public void restore()
+ {
+ Foo foo1 = new Foo();
+ foo1.v1 = 100;
+ foo1._v2 = "hello";
+ RestorePropertiesAction<Object> action = new RestorePropertiesAction<Object>(foo1, "v1",
+ "v2");
+ Foo foo2 = new Foo();
+ action.execute(foo2);
+ assertEquals(foo2.v1, 100);
+ assertEquals(foo2._v2, "hello");
+
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/RestorePropertiesActionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java (added)
+++ tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,112 @@
+// Copyright 2006 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.app2.pages;
+
+import java.io.Serializable;
+
+import org.apache.tapestry.ValueEncoder;
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.corelib.components.Errors;
+import org.apache.tapestry.corelib.components.Form;
+import org.apache.tapestry.corelib.components.Select;
+import org.apache.tapestry.internal.OptionModelImpl;
+import org.apache.tapestry.internal.SelectModelImpl;
+import org.apache.tapestry.validator.Max;
+import org.apache.tapestry.validator.Min;
+
+@ComponentClass
+public class TestPageForSelect
+{
+ public static class HexEncoder implements ValueEncoder<Integer>, Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ public String toClient(Object component, Integer value)
+ {
+ return String.format("%02x", value);
+ }
+
+ public Integer toValue(Object component, String clientValue)
+ {
+ return Integer.parseInt(clientValue, 16);
+ }
+ }
+ public enum Direction { EAST, SOUTH, WEST, NORTH }
+
+ @SuppressWarnings("unused")
+ @Component
+ private Errors _errors;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form1;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form2;
+
+ @Component
+ private Select<Integer> _select1;
+
+ @Component
+ private Select<Direction> _select2;
+
+ @Persist
+ private int v1 = 15; // Pre-select the second option
+
+ @Persist
+ private Direction _v2;
+
+ public Direction getV2()
+ {
+ return _v2;
+ }
+
+ public void setV2(Direction v2)
+ {
+ _v2 = v2;
+ }
+
+ public int getV1()
+ {
+ return v1;
+ }
+
+ public void setV1(int value)
+ {
+ this.v1 = value;
+ }
+
+ public void configureSelect1()
+ {
+ _select1.setLabel("my value");
+ _select1.setValueBindingExpr("v1");
+ _select1.setEncoder(new HexEncoder());
+ _select1.setModel(new SelectModelImpl<Integer>(new OptionModelImpl<Integer>("[1a]", false,
+ 26), new OptionModelImpl<Integer>("[0f]", false, 15), new OptionModelImpl<Integer>(
+ "[ff]", false, 255)));
+ _select1.setValidators(new Min(10), new Max(200));
+ }
+
+ public void configureSelect2()
+ {
+ _select2.setLabel("dir");
+ _select2.setValueBindingExpr("v2");
+ _select2.useDefaultEncoder(Direction.class);
+ _select2.useDefaultModel(Direction.class);
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForSelect.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java (added)
+++ tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,140 @@
+// Copyright 2006 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.app2.pages;
+
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.corelib.components.Errors;
+import org.apache.tapestry.corelib.components.Form;
+import org.apache.tapestry.corelib.components.TextField;
+import org.apache.tapestry.translator.DoubleTranslator;
+import org.apache.tapestry.translator.IntegerTranslator;
+import org.apache.tapestry.validator.Max;
+import org.apache.tapestry.validator.Min;
+
+@ComponentClass
+public class TestPageForTextField
+{
+ @SuppressWarnings("unused")
+ @Component
+ private Errors _errors;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form1;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form2;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form3;
+
+ @SuppressWarnings("unused")
+ @Component
+ private Form _form4;
+
+ @Component
+ private TextField<Integer> _t1;
+
+ @Component(id="t2")
+ private TextField<Double> _t2Field;
+
+ @Component
+ private TextField<Long> _t3;
+
+ @Component
+ private TextField<String> _t4;
+
+ @Persist
+ private int v1;
+
+ @Persist
+ private double t2 = 12.3;
+
+ @Persist
+ private long v3 = 12345;
+
+ @Persist
+ private String v4 = "hello";
+
+ public int getV1()
+ {
+ return v1;
+ }
+
+ public void setV1(int value)
+ {
+ this.v1 = value;
+ }
+
+ public void configureT1()
+ {
+ _t1.setValueBindingExpr("v1");
+ _t1.setTranslator(new IntegerTranslator());
+ _t1.setValidators(new Min(100), new Max(200));
+ }
+
+ public void configureT2()
+ {
+ // Use the default value binding ("t2")
+ _t2Field.setTranslator(new DoubleTranslator());
+ }
+
+ public void configureT3()
+ {
+ // Use the default translator
+ _t3.setValueBindingExpr("v3");
+ }
+
+ public void configureT4()
+ {
+ _t4.setValueBindingExpr("v4");
+ _t4.setDisabled(true);
+ }
+
+ public double getT2()
+ {
+ return t2;
+ }
+
+ public void setT2(double t2)
+ {
+ this.t2 = t2;
+ }
+
+ public long getV3()
+ {
+ return v3;
+ }
+
+ public void setV3(long v3)
+ {
+ this.v3 = v3;
+ }
+
+ public String getV4()
+ {
+ return v4;
+ }
+
+ public void setV4(String v4)
+ {
+ this.v4 = v4;
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTextField.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/tapestry-core/trunk/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/pom.xml?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/pom.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/pom.xml Sun Feb 4 06:40:39 2007
@@ -119,4 +119,4 @@
</plugin>
</plugins>
</reporting>
-</project>
+</project>
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,71 @@
+// 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;
+
+import java.io.Serializable;
+
+import org.apache.tapestry.ioc.internal.util.Defense;
+import org.apache.tapestry.runtime.ComponentResourcesAware;
+
+/**
+ * Uses a binding expression to back a {@link org.apache.tapestry.ValueConduit}.
+ *
+ * @param <T>
+ * the type of the value
+ */
+public class BindingExprValueConduit<T> implements ValueConduit<T>, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String _bindingExpr;
+
+ transient private Binding _binding;
+
+ public BindingExprValueConduit(String bindingExpr)
+ {
+ _bindingExpr = bindingExpr;
+ }
+
+ @SuppressWarnings("unchecked")
+ public T get(Object component)
+ {
+ return (T) getBinding(component).get();
+ }
+
+ public void set(Object component, T value)
+ {
+ getBinding(component).set(value);
+ }
+
+ private Binding getBinding(Object component)
+ {
+ if (_binding == null)
+ {
+ BindingSourceProvider provider = Defense.cast(
+ component,
+ BindingSourceProvider.class,
+ "component");
+ ComponentResourcesAware aware = Defense.cast(
+ component,
+ ComponentResourcesAware.class,
+ "component");
+ _binding = provider.getBindingSource().newBinding(
+ getClass().getSimpleName(),
+ aware.getComponentResources().getContainerResources(),
+ _bindingExpr);
+ }
+ return _binding;
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingExprValueConduit.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,30 @@
+// 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;
+
+import org.apache.tapestry.services.BindingSource;
+
+/**
+ * It allows the {@link org.apache.tapestry.BindingExprValueConduit} to access the
+ * {@link org.apache.tapestry.services.BindingSource} from the
+ * {@link org.apache.tapestry.corelib.base.AbstractField} concerned. Due to classloading issue, it
+ * can't access it as an AbstractField. Instead, it must access it using an interface such as this
+ * one.
+ */
+public interface BindingSourceProvider
+{
+ BindingSource getBindingSource();
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/BindingSourceProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,46 @@
+// 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;
+
+import java.io.Serializable;
+
+/**
+ * Uses a given constant object to back a {@link org.apache.tapestry.ValueConduit}.
+ *
+ * @param <T>
+ * the type of the value
+ */
+public class ConstantValueConduit<T> implements ValueConduit<T>, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private T _value;
+
+ public ConstantValueConduit(T value)
+ {
+ _value = value;
+ }
+
+ public T get(Object component)
+ {
+ return _value;
+ }
+
+ public void set(Object component, T value)
+ {
+ throw new RuntimeException(getClass().getName() + " is read-only");
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ConstantValueConduit.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,35 @@
+// 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;
+
+import java.io.Serializable;
+
+/**
+ * A {@link org.apache.tapestry.ValueEncoder} that treats the value and the clientValue as the same.
+ */
+public class DefaultValueEncoder implements ValueEncoder<String>, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ public String toClient(Object component, String value)
+ {
+ return value;
+ }
+
+ public String toValue(Object component, String clientValue)
+ {
+ return clientValue;
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultValueEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumSelectModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumSelectModel.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumSelectModel.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumSelectModel.java Sun Feb 4 06:40:39 2007
@@ -35,18 +35,18 @@
* <li>As a user-presentable version of the name, i.e., "Local Variable".
* </ul>
*/
-public final class EnumSelectModel implements SelectModel, Serializable
+public final class EnumSelectModel<T extends Enum> implements SelectModel<T>, Serializable
{
private static final long serialVersionUID = -3590412082766899684L;
- private final List<OptionModel> _options = newList();;
+ private final List<OptionModel<T>> _options = newList();;
- public <T extends Enum> EnumSelectModel(Class<T> enumClass, Messages messages)
+ public EnumSelectModel(Class<T> enumClass, Messages messages)
{
this(enumClass, messages, enumClass.getEnumConstants());
}
- public <T extends Enum> EnumSelectModel(Class<T> enumClass, Messages messages, T[] values)
+ public EnumSelectModel(Class<T> enumClass, Messages messages, T[] values)
{
Defense.notNull(enumClass, "enumClass");
Defense.notNull(messages, "messages");
@@ -57,7 +57,7 @@
{
String label = labelForValue(messages, prefix, value);
- _options.add(new OptionModelImpl(label, false, value));
+ _options.add(new OptionModelImpl<T>(label, false, value));
}
}
@@ -77,13 +77,13 @@
}
/** Returns null. */
- public List<OptionGroupModel> getOptionGroups()
+ public List<OptionGroupModel<T>> getOptionGroups()
{
return null;
}
/** Returns the option groupos created in the constructor. */
- public List<OptionModel> getOptions()
+ public List<OptionModel<T>> getOptions()
{
return _options;
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumValueEncoder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumValueEncoder.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumValueEncoder.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/EnumValueEncoder.java Sun Feb 4 06:40:39 2007
@@ -14,30 +14,32 @@
package org.apache.tapestry;
+import java.io.Serializable;
+
import org.apache.tapestry.ioc.internal.util.Defense;
/**
* A value encoder that can be used for aribrary Enum types. The enum name is stored as the client
* side value (the "primary key").
*/
-public class EnumValueEncoder implements ValueEncoder<Enum>
+public class EnumValueEncoder<T extends Enum<T>> implements ValueEncoder<T>, Serializable
{
- private final Class<Enum> _enumType;
+ private static final long serialVersionUID = 1L;
+
+ private final Class<T> _enumType;
- public EnumValueEncoder(final Class<Enum> enumType)
+ public EnumValueEncoder(final Class<T> enumType)
{
Defense.notNull(enumType, "enumType");
-
_enumType = enumType;
}
- public String toClient(Enum value)
+ public String toClient(Object component, T value)
{
return value.name();
}
- @SuppressWarnings("unchecked")
- public Enum toValue(String clientValue)
+ public T toValue(Object component, String clientValue)
{
if (clientValue == null)
return null;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionGroupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionGroupModel.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionGroupModel.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionGroupModel.java Sun Feb 4 06:40:39 2007
@@ -21,7 +21,7 @@
* Defines a group of related options. Options may be enabled or disabled as a group. Corresponds to
* the [X]HTML element <optgroup>.
*/
-public interface OptionGroupModel
+public interface OptionGroupModel<T>
{
/** Localized, user-presentable label for the group. */
String getLabel();
@@ -41,5 +41,5 @@
Map<String, String> getAttributes();
/** The list of options within the group. */
- List<OptionModel> getOptions();
+ List<OptionModel<T>> getOptions();
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionModel.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionModel.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/OptionModel.java Sun Feb 4 06:40:39 2007
@@ -20,7 +20,7 @@
* A single option within a {@link OptionGroupModel}. Corresponds closely to the [X]HTML
* <option> element.
*/
-public interface OptionModel
+public interface OptionModel<T>
{
/** The localized, user-presentable label for the option. */
String getLabel();
@@ -36,5 +36,5 @@
* be selected. It is also used, via {@link ValueEncoder#toClient(Object)}, to generate
* the client-side value attribute.
*/
- Object getValue();
+ T getValue();
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SelectModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SelectModel.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SelectModel.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SelectModel.java Sun Feb 4 06:40:39 2007
@@ -25,14 +25,14 @@
* needs to present a list of options to the user. Generally paired with a {@link ValueEncoder} to
* create client-side representations of server-side values.
*/
-public interface SelectModel
+public interface SelectModel<V>
{
/**
* The list of groups, each containing some number of individual options.
*
* @return the groups, or null
*/
- List<OptionGroupModel> getOptionGroups();
+ List<OptionGroupModel<V>> getOptionGroups();
/**
* The list of ungrouped options, which appear after any grouped options. Generally, a model
@@ -40,5 +40,5 @@
*
* @return the ungrouped options, or null
*/
- List<OptionModel> getOptions();
+ List<OptionModel<V>> getOptions();
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,50 @@
+// 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;
+
+import java.io.Serializable;
+
+/**
+ * TODO: It was meant to allow a page to specify a setter call back. However, it needs to downcast
+ * the component back to its page class, which won't work because the page class is loaded in a
+ * special class loader. One has to create an interface and cast to it instead. This is too much
+ * troublesome. Because most usually only the setter is used on form submission but the value is
+ * not, the value is not serialized.
+ */
+public class SetterValueConduit<T> implements ValueConduit<T>, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ transient private T _value;
+
+ private ValueSetter<T> _setter;
+
+ public SetterValueConduit(T value, ValueSetter<T> setter)
+ {
+ _value = value;
+ _setter = setter;
+ }
+
+ public T get(Object component)
+ {
+ return _value;
+ }
+
+ public void set(Object component, T value)
+ {
+ _setter.set(component, value);
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/SetterValueConduit.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java Sun Feb 4 06:40:39 2007
@@ -23,24 +23,9 @@
* <p>
* Validators are usually encapsulated inside a {@link FieldValidator}.
*/
-public interface Validator<C, T>
+public interface Validator<T>
{
/**
- * Returns the type of constraint value used with this validator. Constraint values are used to
- * parameterize a validator, for example a "maxLength" validator will have a constraint value of
- * type int (the maximum length allowed). For constraints that do not have a constraint value,
- * this method returns null.
- */
- Class<C> getConstraintType();
-
- /**
- * Returns the value type associated with this validator.
- * {@link #validate(Field, Object, MessageFormatter, Object)} will only be invoked when the
- * value is assignable to the validator's value type.
- */
- Class<T> getValueType();
-
- /**
* Returns the message key, within the validiation messages, normally used by this validator.
* This is used to provide the {@link MessageFormatter} passed to
* {@link #validate(Field, Object, MessageFormatter, Object)} (unless overridden).
@@ -57,8 +42,6 @@
*
* @param field
* the field for which a client submitted value is being validated
- * @param constraintValue
- * the value used to constrain
* @param formatter
* Validation messages, in the appropriate locale
* @param value
@@ -66,8 +49,7 @@
* @throws ValidationException
* if the value violates the constraint
*/
- void validate(Field field, C constraintValue, MessageFormatter formatter, T value)
- throws ValidationException;
+ void validate(Field field, MessageFormatter formatter, T value) throws ValidationException;
/**
* Returns true if the validator should be invoked for null or blank (empty string) values. This
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,26 @@
+package org.apache.tapestry;
+
+public interface ValueConduit<T>
+{
+ /**
+ * Reads the current value of a certain property (or other resource) of the container of a given
+ * component. When reading properties of objects that are primitive types, this will return an
+ * instance of the wrapper type. In some cases, a value holder is write-only and this method
+ * will throw a runtime exception.
+ *
+ * @param component
+ * the component that is looking for the value
+ */
+ T get(Object component);
+
+ /**
+ * Updates the current value. Some value holders are read-only, and this method will throw a
+ * runtime exception.
+ *
+ * @param component
+ * the component that is updating the value
+ * @param value
+ */
+ void set(Object component, T value);
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueConduit.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueEncoder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueEncoder.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueEncoder.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueEncoder.java Sun Feb 4 06:40:39 2007
@@ -22,26 +22,30 @@
*
* @see SelectModel
*/
-public interface ValueEncoder<V>
+public interface ValueEncoder<T>
{
/**
* Converts a value into a client-side representation. The value should be parseable by
* {@link #toValue(String)}. In some cases, what is returned is an identifier used to locate
* the true object, rather than a string representation of the value itself.
*
+ * @param component
+ * the component such as a {@link Select} whose value is being encoded.
* @param value
* to be encoded
* @return a string representation of the value, or the value's identity
*/
- String toClient(V value);
+ String toClient(Object component, T value);
/**
* Converts a client-side representation, provided by {@link #toClient(Object)}, back into a
* server-side value.
*
+ * @param component
+ * the component such as a {@link Select} whose value is being decoded.
* @param clientValue
* string representation of the value's identity
* @return the corresponding entity, or null if not found
*/
- V toValue(String clientValue);
+ T toValue(Object component, String clientValue);
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,6 @@
+package org.apache.tapestry;
+
+public interface ValueSetter<T>
+{
+ void set(Object component, T value);
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ValueSetter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,39 @@
+// 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.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marker annotation placed on fields whose value should persist across the rendering and submission
+ * of a form. That is, the values will be saved into a hidden form field. On form submission, the
+ * values will be restored just before the
+ * {@link org.apache.tapestry.corelib.base.AbstractField#processSubmission()} is called.
+ * <p>
+ * It doesn't fit in as a persistent field strategy because such persistent fields are restored at
+ * the moment the page is attached, which doesn't work for form submissions and doesn't work if the
+ * component is in a loop.
+ */
+@Target(FIELD)
+@Retention(RUNTIME)
+@Documented
+public @interface FormPersist {
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/FormPersist.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,34 @@
+//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.beaneditor;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation to a String property to indicate that its length is limited.
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface LengthRange {
+ int minLength() default 0;
+
+ int maxLength() default Integer.MAX_VALUE;
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/LengthRange.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,32 @@
+//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.beaneditor;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation to a number property to indicate that its maximum value.
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface Max {
+ long value();
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Max.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,32 @@
+//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.beaneditor;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation to a number property to indicate that its minimum value.
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface Min {
+ long value();
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Min.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,31 @@
+//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.beaneditor;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation to a property to indicate that it's mandatory.
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface Required {
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/Required.java
------------------------------------------------------------------------------
svn:eol-style = native
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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb 4 06:40:39 2007
@@ -15,32 +15,32 @@
package org.apache.tapestry.corelib.base;
import java.io.Serializable;
+import java.util.List;
-import org.apache.tapestry.Binding;
+import org.apache.tapestry.BindingSourceProvider;
import org.apache.tapestry.ComponentAction;
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.Field;
import org.apache.tapestry.FieldValidator;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.ValidationDecorator;
-import org.apache.tapestry.ValidationException;
import org.apache.tapestry.annotations.AfterRender;
import org.apache.tapestry.annotations.BeginRender;
+import org.apache.tapestry.annotations.CleanupRender;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.FormPersist;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Mixin;
-import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.SetupRender;
import org.apache.tapestry.corelib.mixins.DiscardBody;
import org.apache.tapestry.corelib.mixins.RenderDisabled;
import org.apache.tapestry.corelib.mixins.RenderInformals;
+import org.apache.tapestry.corelib.mixins.TypeSafeConfigurationEnabled;
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.ioc.services.PropertyAccess;
-import org.apache.tapestry.runtime.Component;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.FormSupport;
import org.apache.tapestry.services.PageRenderSupport;
@@ -50,16 +50,20 @@
* {@link RenderInformals}, {@link RenderDisabled} and {@link DiscardBody} mixins.
*/
@ComponentClass
-public abstract class AbstractField implements Field
+public abstract class AbstractField implements Field, BindingSourceProvider
{
+ @SuppressWarnings("unused")
+ @Mixin
+ private TypeSafeConfigurationEnabled _typeSafeConfigurationEnabled;
+
/**
* The user presentable label for the field. If not provided, a reasonable label is generated
* from the component's id.
*/
- @Parameter(defaultPrefix = "literal")
+ @FormPersist
private String _label;
- @Parameter
+ @FormPersist
private boolean _disabled;
@SuppressWarnings("unused")
@@ -77,13 +81,7 @@
@Environmental
private ValidationDecorator _decorator;
- protected static final FieldValidator NOOP_VALIDATOR = new FieldValidator()
- {
- public void validate(Object value) throws ValidationException
- {
- // Do nothing
- }
- };
+ protected static final FieldValidator NOOP_VALIDATOR = new NoOpFieldValidator();
static class SetupAction implements ComponentAction<AbstractField>, Serializable
{
@@ -115,7 +113,6 @@
/** Used a shared instance for all types of fields, for efficiency. */
private static final ProcessSubmissionAction PROCESS_SUBMISSION_ACTION = new ProcessSubmissionAction();
- @Parameter(value = "prop:componentResources.id", defaultPrefix="literal")
private String _clientId;
private String _assignedClientId;
@@ -137,10 +134,7 @@
@Inject("infrastructure:BindingSource")
private BindingSource _bindingSource;
- @Inject("infrastructure:PropertyAccess")
- private PropertyAccess _propertyAccess;
-
- final Binding defaultLabel()
+ final String getDefaultLabel()
{
Messages containerMessages = _resources.getContainer().getComponentResources()
.getMessages();
@@ -152,14 +146,12 @@
String label = containerMessages.contains(key) ? containerMessages.get(key) : TapestryUtils
.toUserPresentable(componentId);
- // Bypassing the BindingSource for this ...
-
- return new LiteralBinding("default label", label, null);
+ return label;
}
public final String getLabel()
{
- return _label;
+ return _label == null ? getDefaultLabel() : _label;
}
@SetupRender
@@ -167,7 +159,10 @@
{
// By default, use the component id as the (base) client id. If the clientid
// parameter is bound, then that is the value to use.
-
+ if (_clientId == null)
+ {
+ useDefaultClientId();
+ }
String id = _clientId;
// Often, these elementName and _clientId will end up as the same value. There are many
@@ -178,9 +173,38 @@
String elementName = _formSupport.allocateElementName(id);
_formSupport.storeAndExecute(this, new SetupAction(elementName));
+ }
+
+ private void useDefaultClientId()
+ {
+ _clientId = _resources.getId();
+ }
+
+ @CleanupRender
+ final void cleanupRender()
+ {
+ // Can't store properties in setup() because some times they're set to
+ // default values during rendering.
+ List<String> formPersistPropNames = CollectionFactory.newList();
+ collectFormPersistPropNames(formPersistPropNames);
+ _formSupport.store(this, new RestorePropertiesAction<AbstractField>(this,
+ formPersistPropNames.toArray(new String[0])));
+ // Process form submission after the properties are restored.
_formSupport.store(this, PROCESS_SUBMISSION_ACTION);
}
+ /**
+ * Add the list of names of the properties whose values will be restored on form submission. The
+ * {@link org.apache.tapestry.internal.services.FormPersistWorker} will a
+ * {@link #collectFormPersistPropNames(List)} method in a sub-class to call this method and then
+ * add its own property names. Actually, it will replace this method with one that adds form
+ * persistent property names declared in this class.
+ */
+ protected void collectFormPersistPropNames(List<String> formPersistPropNames)
+ {
+
+ }
+
public final String getClientId()
{
return _assignedClientId;
@@ -211,34 +235,6 @@
}
/**
- * 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
- */
- protected final Binding createDefaultParameterBinding(String parameterName)
- {
- String componentId = _resources.getId();
-
- Component container = _resources.getContainer();
-
- // Only provide a default binding if the container actually contains the property.
- // This sets up an error condition for when the value parameter is not bound, and
- // the binding can't be deduced.
-
- if (_propertyAccess.getAdapter(container).getPropertyAdapter(componentId) == null)
- return null;
-
- ComponentResources containerResources = _resources.getContainerResources();
-
- return _bindingSource.newBinding(
- "default " + parameterName,
- containerResources,
- 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
* invoked if the field is <strong>not {@link #isDisabled() disabled}</strong>.
@@ -268,5 +264,30 @@
protected final ValidationDecorator getValidationDecorator()
{
return _decorator;
+ }
+
+ public void setDisabled(boolean disabled)
+ {
+ _disabled = disabled;
+ }
+
+ public void setLabel(String label)
+ {
+ _label = label;
+ }
+
+ public String getIdBasedBindingExpression()
+ {
+ return _resources.getId();
+ }
+
+ public BindingSource getBindingSource()
+ {
+ return _bindingSource;
+ }
+
+ public void setClientId(String clientId)
+ {
+ _clientId = clientId;
}
}
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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb 4 06:40:39 2007
@@ -16,39 +16,41 @@
import java.util.Locale;
-import org.apache.tapestry.Binding;
-import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.BindingExprValueConduit;
import org.apache.tapestry.FieldValidator;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.Translator;
import org.apache.tapestry.ValidationException;
import org.apache.tapestry.ValidationTracker;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ValueConduit;
import org.apache.tapestry.annotations.AfterRender;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.FormPersist;
import org.apache.tapestry.annotations.Inject;
-import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.internal.services.FieldValidatorImpl;
+import org.apache.tapestry.internal.services.FieldValidatorMessages;
import org.apache.tapestry.internal.services.FormParameterLookup;
import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.services.FieldValidatorDefaultSource;
import org.apache.tapestry.services.TranslatorDefaultSource;
import org.apache.tapestry.services.ValidationMessagesSource;
+import org.apache.tapestry.translator.StringTranslator;
/**
* 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.
*/
-public abstract class AbstractTextField extends AbstractField
+public abstract class AbstractTextField<T> extends AbstractField
{
- @Parameter(required = true, principal = true)
- private Object _value;
+ @FormPersist
+ private ValueConduit<T> _valueConduit;
- @Parameter
- private Translator<Object> _translate;
+ @FormPersist
+ private Translator<T> _translator;
- @Parameter(defaultPrefix = "validate")
- @SuppressWarnings("unchecked")
- private FieldValidator<Object> _validate = NOOP_VALIDATOR;
+ @FormPersist
+ private Validator<? super T>[] _validators;
@Environmental
private ValidationTracker _tracker;
@@ -56,76 +58,49 @@
@Inject("infrastructure:ValidationMessagesSource")
private ValidationMessagesSource _messagesSource;
+ @Inject("infrastructure:FieldValidatorMessages")
+ private FieldValidatorMessages _fieldValidatorMessages;
+
@Inject("infrastructure:TranslatorDefaultSource")
private TranslatorDefaultSource _translatorDefaultSource;
- @Inject("infrastructure:FieldValidatorDefaultSource")
- private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
-
- @Inject
- private ComponentResources _resources;
-
@Inject
private Locale _locale;
- /**
- * Computes a default value for the "translate" parameter using {@link TranslatorDefaultSource}.
- */
- final Translator defaultTranslate()
- {
- // Because the value parameter is a principal parameter, we know that it will be bound (even
- // via its default parameter) by the time this method is invoked.
-
- Class type = _resources.getBoundType("value");
-
- if (type == null)
- return null;
-
- return _translatorDefaultSource.find(type);
- }
-
- /**
- * Computes a default value for the "validate" parameter using
- * {@link FieldValidatorDefaultSource}.
- */
- final FieldValidator defaultValidate()
- {
- Class type = _resources.getBoundType("value");
-
- if (type == null)
- return null;
-
- return _fieldValidatorDefaultSource.createDefaultValidator(
- this,
- _resources.getId(),
- _resources.getContainerMessages(),
- _locale,
- type,
- _resources.getAnnotationProvider("value"));
- }
-
- /**
- * 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.
- */
- final Binding defaultValue()
- {
- return createDefaultParameterBinding("value");
- }
-
+ @SuppressWarnings("unchecked")
@BeginRender
final void begin(MarkupWriter writer)
{
+ // Need to use defaults if they're unspecified, even if the tracker already contains
+ // a value. Otherwise, they will remain as null and when the form is submitted,
+ // we'll be in trouble.
+ if (_valueConduit == null)
+ {
+ setValueBindingExpr(getIdBasedBindingExpression());
+ }
+ T rawValue = _valueConduit.get(this);
+ if (_translator == null)
+ {
+ useDefaultTranslator(rawValue);
+ }
String value = _tracker.getInput(this);
if (value == null)
- value = _translate.toClient(_value);
-
+ {
+ value = _translator.toClient(rawValue);
+ }
writeFieldTag(writer, value);
getValidationDecorator().insideField(this);
}
+ @SuppressWarnings("unchecked")
+ private void useDefaultTranslator(T rawValue)
+ {
+ _translator = rawValue != null ? _translatorDefaultSource.find(rawValue.getClass())
+ : new StringTranslator();
+ }
+
/**
* Invoked from {@link #begin(MarkupWriter)} to write out the element and attributes (typically,
* <input>). The {@link AbstractField#getElementName() elementName} and
@@ -155,11 +130,13 @@
try
{
- Object translated = _translate.parseClient(rawValue, messages);
+ T translated = _translator.parseClient(rawValue, messages);
- _validate.validate(translated);
+ FieldValidator<T> fieldValidator = new FieldValidatorImpl<T>(this,
+ _fieldValidatorMessages, _validators);
+ fieldValidator.validate(translated);
- _value = translated;
+ _valueConduit.set(this, translated);
}
catch (ValidationException ex)
{
@@ -167,4 +144,41 @@
return;
}
}
-}
+
+ public void setValidators(Validator<? super T>... validators)
+ {
+ _validators = validators;
+ }
+
+ public Translator<T> getTranslator()
+ {
+ return _translator;
+ }
+
+ public Validator<? super T>[] getValidators()
+ {
+ return _validators;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setValueBindingExpr(String valueBindingExpr)
+ {
+ _valueConduit = new BindingExprValueConduit(valueBindingExpr);
+ }
+
+ public void setTranslator(Translator<T> translator)
+ {
+ _translator = translator;
+ }
+
+ public ValueConduit<T> getValueConduit()
+ {
+ return _valueConduit;
+ }
+
+ public void setValueConduit(ValueConduit<T> valueHolder)
+ {
+ _valueConduit = valueHolder;
+ }
+
+}
\ No newline at end of file
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,30 @@
+//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.corelib.base;
+
+import java.io.Serializable;
+
+import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.ValidationException;
+
+public class NoOpFieldValidator implements FieldValidator, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ public void validate(Object value) throws ValidationException
+ {
+ // Do nothing
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/NoOpFieldValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java Sun Feb 4 06:40:39 2007
@@ -0,0 +1,73 @@
+// 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.corelib.base;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.io.Serializable;
+
+import org.apache.tapestry.ComponentAction;
+import org.apache.tapestry.ioc.internal.services.PropertyAdapterImpl;
+import org.apache.tapestry.ioc.services.PropertyAdapter;
+
+/**
+ * A {@link org.apache.tapestry.ComponentAction} that stores in it the specified property names and
+ * values of a given component. On execution, it will restore the values into the component.
+ *
+ * @param <T>
+ * the type of the component
+ * @see org.apache.tapestry.annotations.FormPersist
+ */
+public class RestorePropertiesAction<T> implements ComponentAction<T>, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private final String[] _propertyNames;
+
+ private final Object[] _propertyValues;
+
+ public RestorePropertiesAction(Object component, String... propertyNames)
+ {
+ _propertyNames = propertyNames;
+ _propertyValues = new Object[_propertyNames.length];
+ for (int i = 0; i < _propertyNames.length; i++)
+ {
+ _propertyValues[i] = getPropertyAdaptor(component.getClass(), i).get(component);
+ }
+ }
+
+ public void execute(T component)
+ {
+ for (int i = 0; i < _propertyNames.length; i++)
+ {
+ getPropertyAdaptor(component.getClass(), i).set(component, _propertyValues[i]);
+ }
+ }
+
+ private PropertyAdapter getPropertyAdaptor(Class<?> clazz, int i)
+ {
+ String propertyName = _propertyNames[i];
+ PropertyDescriptor pd;
+ try
+ {
+ pd = new PropertyDescriptor(propertyName, clazz);
+ }
+ catch (IntrospectionException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ return new PropertyAdapterImpl(pd);
+ }
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/RestorePropertiesAction.java
------------------------------------------------------------------------------
svn:eol-style = native