You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/06/04 19:36:42 UTC
svn commit: r544192 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry/
main/java/org/apache/tapestry/corelib/components/
main/java/org/apache/tapestry/corelib/pages/
main/java/org/apache/tapestry/internal/services/ main/ja...
Author: hlship
Date: Mon Jun 4 10:36:38 2007
New Revision: 544192
URL: http://svn.apache.org/viewvc?view=rev&rev=544192
Log:
TAPESTRY-1501: Remove Img component
TAPESTRY-1503: BeanEditForm should default its object parameter to container property that matches its id
TAPESTRY-1465: BeanEditForm and Grid are not extensible in terms of supported property types to be editted or viewed
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/BeanBlockSourceImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TransformationException.java
- copied, changed from r542287, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ioc/internal/TransformationException.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockContribution.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockSource.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyDisplayContext.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.html
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyEditBlocks.html
tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/beaneditform.apt
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanBlockSourceImplTest.java
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Img.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ioc/internal/TransformationException.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridCell.html
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BlockNotFoundException.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridCell.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridColumns.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/DataTypeAnalyzer.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.properties
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridColumns.html
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
tapestry/tapestry5/trunk/tapestry-core/src/site/site.xml
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/BeanEditorDemo.html
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/BeanEditFormTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/ProgrammingLanguage.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BlockNotFoundException.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BlockNotFoundException.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BlockNotFoundException.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/BlockNotFoundException.java Mon Jun 4 10:36:38 2007
@@ -18,7 +18,7 @@
import org.apache.tapestry.ioc.Location;
/**
- * Exception thrown when a a {@link Block} is requested but not found.
+ * Exception thrown when a {@link Block} is requested but not found.
*/
public class BlockNotFoundException extends RuntimeException implements Locatable
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java Mon Jun 4 10:36:38 2007
@@ -16,15 +16,14 @@
import java.util.Locale;
+import org.apache.tapestry.Binding;
import org.apache.tapestry.Block;
import org.apache.tapestry.ClientElement;
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.Field;
import org.apache.tapestry.FieldValidator;
import org.apache.tapestry.FormValidationControl;
-import org.apache.tapestry.SelectModel;
import org.apache.tapestry.Translator;
-import org.apache.tapestry.ValueEncoder;
import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Parameter;
@@ -33,11 +32,13 @@
import org.apache.tapestry.beaneditor.PropertyModel;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.internal.util.TapestryException;
+import org.apache.tapestry.services.BeanBlockSource;
+import org.apache.tapestry.services.PropertyEditContext;
import org.apache.tapestry.services.BeanModelSource;
+import org.apache.tapestry.services.DefaultComponentParameterBindingSource;
+import org.apache.tapestry.services.Environment;
import org.apache.tapestry.services.FieldValidatorDefaultSource;
import org.apache.tapestry.services.TranslatorDefaultSource;
-import org.apache.tapestry.util.EnumSelectModel;
-import org.apache.tapestry.util.EnumValueEncoder;
/**
* A component that creates an entire form editting the properties of a particular bean. Inspired by
@@ -90,34 +91,9 @@
@Inject
private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
- @Inject
- private Block _text;
-
- @Inject
- private Block _enum;
-
- @Inject
- private Block _checkbox;
-
@Component(parameters = "clientValidation=clientValidation")
private Form _form;
- @Component(parameters =
- { "value=valueForProperty", "label=prop:propertyEditModel.label",
- "encoder=valueEncoderForProperty", "model=selectModelForProperty",
- "validate=prop:validateForProperty", "clientId=prop:propertyName" })
- private Select _select;
-
- @Component(parameters =
- { "value=valueForProperty", "label=prop:propertyEditModel.label",
- "translate=prop:translateForProperty", "validate=prop:validateForProperty",
- "clientId=prop:propertyName" })
- private TextField _textField;
-
- @Component(parameters =
- { "value=valueForProperty", "label=prop:propertyEditModel.label", "clientId=prop:propertyName" })
- private Checkbox _checkboxField;
-
@Inject
private Messages _messages;
@@ -140,7 +116,24 @@
private Block _blockForProperty;
- private Field _fieldForProperty;
+ @Inject
+ private DefaultComponentParameterBindingSource _defaultBindingSource;
+
+ @Inject
+ private Environment _environment;
+
+ @Inject
+ private BeanBlockSource _beanBlockSource;
+
+ private boolean _mustPopBeanEditContext;
+
+ /**
+ * Defaults the object parameter to a property of the container matching the BeanEditForm's id.
+ */
+ Binding defaultObject()
+ {
+ return _defaultBindingSource.createDefaultBinding("object", _resources);
+ }
public BeanModel getModel()
{
@@ -159,7 +152,6 @@
_propertyEditModel = _model.get(propertyName);
_blockForProperty = null;
- _fieldForProperty = null;
Block override = _resources.getBlockParameter(_propertyEditModel.getId());
@@ -171,32 +163,74 @@
String dataType = _propertyEditModel.getDataType();
- if (dataType.equals("text"))
+ try
{
- _blockForProperty = _text;
- _fieldForProperty = _textField;
- return;
+ _blockForProperty = _beanBlockSource.getEditBlock(dataType);
}
-
- if (dataType.equals("enum"))
+ catch (RuntimeException ex)
{
- _blockForProperty = _enum;
- _fieldForProperty = _select;
- return;
- }
+ String message = _messages.format("block-error", _propertyName, dataType, _object, ex);
- if (dataType.equals("checkbox"))
- {
- _blockForProperty = _checkbox;
- _fieldForProperty = _checkboxField;
- return;
+ throw new TapestryException(message, _resources.getLocation(), ex);
}
-
- throw new IllegalArgumentException(_messages.format("no-editor", dataType, propertyName));
}
boolean onPrepareFromForm()
{
+ PropertyEditContext context = new PropertyEditContext()
+ {
+ public Messages getContainerMessages()
+ {
+ return getResources().getContainerMessages();
+ }
+
+ public String getLabel()
+ {
+ return getPropertyEditModel().getLabel();
+ }
+
+ public String getPropertyId()
+ {
+ return getPropertyEditModel().getId();
+ }
+
+ public Class getPropertyType()
+ {
+ return getPropertyEditModel().getPropertyType();
+ }
+
+ public Object getPropertyValue()
+ {
+ return getPropertyEditModel().getConduit().get(getObject());
+ }
+
+ public Translator getTranslator()
+ {
+ return _translatorDefaultSource.find(getPropertyEditModel().getPropertyType());
+ }
+
+ public FieldValidator getValidator(Field field)
+ {
+ return _fieldValidatorDefaultSource.createDefaultValidator(
+ field,
+ _propertyName,
+ _resources.getContainerMessages(),
+ _locale,
+ _propertyEditModel.getPropertyType(),
+ _propertyEditModel.getConduit());
+ }
+
+ public void setPropertyValue(Object value)
+ {
+ getPropertyEditModel().getConduit().set(getObject(), value);
+ }
+ };
+
+ _environment.push(PropertyEditContext.class, context);
+ // Depending on whether we're rendering or processing the form submission we'll have two
+ // different places to clean up the Environment.
+ _mustPopBeanEditContext = true;
+
// Fire a new prepare event to be consumed by the container. This is the container's
// chance to ensure that there's an object to edit.
@@ -222,10 +256,31 @@
return true; // abort the form's prepare event
}
- void inject(ComponentResources resources, BeanModelSource modelSource)
+ private void cleanupBeanEditContext()
+ {
+ if (_mustPopBeanEditContext)
+ {
+ _environment.pop(PropertyEditContext.class);
+ _mustPopBeanEditContext = false;
+ }
+ }
+
+ void onSubmit()
+ {
+ cleanupBeanEditContext();
+ }
+
+ void afterRender()
+ {
+ cleanupBeanEditContext();
+ }
+
+ /** Used for testing. */
+ void inject(ComponentResources resources, BeanModelSource modelSource, Environment environment)
{
_resources = resources;
_modelSource = modelSource;
+ _environment = environment;
}
Object getObject()
@@ -250,57 +305,11 @@
}
}
- public Translator getTranslateForProperty()
- {
- return _translatorDefaultSource.find(_propertyEditModel.getPropertyType());
- }
-
- public FieldValidator getValidateForProperty()
- {
- return _fieldValidatorDefaultSource.createDefaultValidator(
- _fieldForProperty,
- _propertyName,
- _resources.getContainerMessages(),
- _locale,
- _propertyEditModel.getPropertyType(),
- _propertyEditModel.getConduit());
- }
-
- public PropertyModel getPropertyEditModel()
- {
- return _propertyEditModel;
- }
-
public Block getBlockForProperty()
{
return _blockForProperty;
}
- public Object getValueForProperty()
- {
- return _propertyEditModel.getConduit().get(_object);
- }
-
- public void setValueForProperty(Object value)
- {
- _propertyEditModel.getConduit().set(_object, value);
- }
-
- /** Provide a value encoder for an enum type. */
- @SuppressWarnings("unchecked")
- public ValueEncoder getValueEncoderForProperty()
- {
- return new EnumValueEncoder(_propertyEditModel.getPropertyType());
- }
-
- /** Provide a select mode for an enum type. */
- @SuppressWarnings("unchecked")
- public SelectModel getSelectModelForProperty()
- {
- return new EnumSelectModel(_propertyEditModel.getPropertyType(), _resources
- .getContainerMessages());
- }
-
/** Returns the client id of the embedded form. */
public String getClientId()
{
@@ -340,6 +349,16 @@
public void recordError(String errorMessage)
{
_form.recordError(errorMessage);
+ }
+
+ private ComponentResources getResources()
+ {
+ return _resources;
+ }
+
+ private PropertyModel getPropertyEditModel()
+ {
+ return _propertyEditModel;
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridCell.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridCell.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridCell.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridCell.java Mon Jun 4 10:36:38 2007
@@ -20,7 +20,10 @@
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.beaneditor.PropertyModel;
-import org.apache.tapestry.internal.TapestryInternalUtils;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.services.BeanBlockSource;
+import org.apache.tapestry.services.Environment;
+import org.apache.tapestry.services.PropertyDisplayContext;
/**
* Part of {@link Grid} that renders a single data cell. GridCell is used inside a pair of loops;
@@ -49,17 +52,46 @@
@Inject
private ComponentResources _gridCellResources;
+ @Inject
+ private BeanBlockSource _beanBlockSource;
+
+ @Inject
+ private Environment _environment;
+
+ private boolean _mustPopEnvironment;
+
Object beginRender(MarkupWriter writer)
{
Block override = _resources.getBlockParameter(_model.getId() + "Cell");
- if (override != null)
- return override;
+ if (override != null) return override;
+
+ String datatype = _model.getDataType();
+
+ if (_beanBlockSource.hasDisplayBlock(datatype))
+ {
+ PropertyDisplayContext context = new PropertyDisplayContext()
+ {
+ public Messages getContainerMessages()
+ {
+ return GridCell.this.getContainerMessages();
+ }
+
+ public Object getPropertyValue()
+ {
+ return readPropertyForRow();
+ }
+ };
+
+ _environment.push(PropertyDisplayContext.class, context);
+ _mustPopEnvironment = true;
+
+ return _beanBlockSource.getDisplayBlock(datatype);
+ }
- Block builtin = _gridCellResources.findBlock(_model.getDataType());
+ Block block = _gridCellResources.findBlock(datatype);
- if (builtin != null)
- return builtin;
+ if (block != null) return block;
Object value = _model.getConduit().get(_row);
@@ -76,6 +108,16 @@
return false;
}
+ private Object readPropertyForRow()
+ {
+ return _model.getConduit().get(_row);
+ }
+
+ private Messages getContainerMessages()
+ {
+ return _resources.getMessages();
+ }
+
/*
* When rendering a Block instead of a literal value, the template will start to render but its
* is effectively just some whitespace and we want to skip it entirely.
@@ -85,13 +127,12 @@
return false;
}
- public String getConvertedEnumValue()
+ void afterRender()
{
- Enum value = (Enum) _model.getConduit().get(_row);
-
- if (value == null)
- return null;
-
- return TapestryInternalUtils.getLabelForEnum(_resources.getMessages(), value);
+ if (_mustPopEnvironment)
+ {
+ _environment.pop(PropertyDisplayContext.class);
+ _mustPopEnvironment = false;
+ }
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridColumns.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridColumns.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridColumns.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/GridColumns.java Mon Jun 4 10:36:38 2007
@@ -129,5 +129,5 @@
public String getCellClass()
{
return _columnModel.getId() + "-header";
- }
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.java Mon Jun 4 10:36:38 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.corelib.pages;
+
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.internal.TapestryInternalUtils;
+import org.apache.tapestry.services.PropertyDisplayContext;
+
+public class PropertyDisplayBlocks
+{
+ @Environmental
+ private PropertyDisplayContext _context;
+
+ public String getConvertedEnumValue()
+ {
+ Enum value = (Enum) _context.getPropertyValue();
+
+ if (value == null) return null;
+
+ return TapestryInternalUtils.getLabelForEnum(_context.getContainerMessages(), value);
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,89 @@
+// 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.pages;
+
+import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.SelectModel;
+import org.apache.tapestry.ValueEncoder;
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.corelib.components.BeanEditForm;
+import org.apache.tapestry.corelib.components.Checkbox;
+import org.apache.tapestry.corelib.components.Select;
+import org.apache.tapestry.corelib.components.TextField;
+import org.apache.tapestry.services.BeanBlockContribution;
+import org.apache.tapestry.services.BeanBlockSource;
+import org.apache.tapestry.services.PropertyEditContext;
+import org.apache.tapestry.util.EnumSelectModel;
+import org.apache.tapestry.util.EnumValueEncoder;
+
+/**
+ * A page that exists to contain blocks used to edit different types of properties. The blocks on
+ * this page are contributed into the {@link BeanBlockSource} service configuration.
+ *
+ * @see BeanBlockContribution
+ * @see BeanEditForm
+ */
+public class PropertyEditBlocks
+{
+ @Environmental
+ private PropertyEditContext _context;
+
+ @Component(parameters =
+ { "value=context.propertyValue", "label=prop:context.label",
+ "translate=prop:context.translator", "validate=prop:textFieldValidator",
+ "clientId=prop:context.propertyId" })
+ private TextField _textField;
+
+ @Component(parameters =
+ { "value=context.propertyValue", "label=prop:context.label", "encoder=valueEncoderForProperty",
+ "model=selectModelForProperty", "validate=prop:selectValidator",
+ "clientId=prop:context.propertyId" })
+ private Select _select;
+
+ @SuppressWarnings("unused")
+ @Component(parameters =
+ { "value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyId" })
+ private Checkbox _checkboxField;
+
+ public PropertyEditContext getContext()
+ {
+ return _context;
+ }
+
+ public FieldValidator getTextFieldValidator()
+ {
+ return _context.getValidator(_textField);
+ }
+
+ public FieldValidator getSelectValidator()
+ {
+ return _context.getValidator(_select);
+ }
+
+ /** Provide a value encoder for an enum type. */
+ @SuppressWarnings("unchecked")
+ public ValueEncoder getValueEncoderForProperty()
+ {
+ return new EnumValueEncoder(_context.getPropertyType());
+ }
+
+ /** Provide a select mode for an enum type. */
+ @SuppressWarnings("unchecked")
+ public SelectModel getSelectModelForProperty()
+ {
+ return new EnumSelectModel(_context.getPropertyType(), _context.getContainerMessages());
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/BeanBlockSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/BeanBlockSourceImpl.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/BeanBlockSourceImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/BeanBlockSourceImpl.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,82 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newCaseInsensitiveMap;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.tapestry.Block;
+import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.services.BeanBlockContribution;
+import org.apache.tapestry.services.BeanBlockSource;
+
+public class BeanBlockSourceImpl implements BeanBlockSource
+{
+ private final RequestPageCache _pageCache;
+
+ private final Map<String, BeanBlockContribution> _display = newCaseInsensitiveMap();
+
+ private final Map<String, BeanBlockContribution> _edit = newCaseInsensitiveMap();
+
+ public BeanBlockSourceImpl(RequestPageCache pageCache,
+ Collection<BeanBlockContribution> configuration)
+ {
+ _pageCache = pageCache;
+
+ for (BeanBlockContribution contribution : configuration)
+ {
+ Map<String, BeanBlockContribution> map = contribution.isEdit() ? _edit : _display;
+
+ // TODO: Check for conflicts?
+
+ map.put(contribution.getDataType(), contribution);
+ }
+ }
+
+ public boolean hasDisplayBlock(String datatype)
+ {
+ return _display.containsKey(datatype);
+ }
+
+ public Block getDisplayBlock(String datatype)
+ {
+ BeanBlockContribution contribution = _display.get(datatype);
+
+ if (contribution == null)
+ throw new RuntimeException(ServicesMessages.noDisplayForDataType(datatype));
+
+ return toBlock(contribution);
+ }
+
+ private Block toBlock(BeanBlockContribution contribution)
+ {
+ Page page = _pageCache.get(contribution.getPageName());
+
+ return page.getRootElement().getBlock(contribution.getBlockId());
+ }
+
+ public Block getEditBlock(String datatype)
+ {
+ BeanBlockContribution contribution = _edit.get(datatype);
+
+ if (contribution == null)
+ throw new RuntimeException(ServicesMessages.noEditForDataType(datatype));
+
+ return toBlock(contribution);
+ }
+
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java Mon Jun 4 10:36:38 2007
@@ -28,7 +28,6 @@
import org.apache.tapestry.internal.model.MutableComponentModelImpl;
import org.apache.tapestry.ioc.LogSource;
import org.apache.tapestry.ioc.Resource;
-import org.apache.tapestry.ioc.internal.TransformationException;
import org.apache.tapestry.ioc.internal.util.ClasspathResource;
import org.apache.tapestry.model.ComponentModel;
import org.apache.tapestry.model.MutableComponentModel;
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java Mon Jun 4 10:36:38 2007
@@ -393,4 +393,14 @@
{
return MESSAGES.format("unclosed-attribute-expression", expression);
}
+
+ static String noDisplayForDataType(String datatype)
+ {
+ return MESSAGES.format("no-display-for-data-type", datatype);
+ }
+
+ static String noEditForDataType(String datatype)
+ {
+ return MESSAGES.format("no-edit-for-data-type", datatype);
+ }
}
Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TransformationException.java (from r542287, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ioc/internal/TransformationException.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TransformationException.java?view=diff&rev=544192&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ioc/internal/TransformationException.java&r1=542287&p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TransformationException.java&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ioc/internal/TransformationException.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TransformationException.java Mon Jun 4 10:36:38 2007
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.internal;
+package org.apache.tapestry.internal.services;
import org.apache.tapestry.ioc.internal.util.TapestryException;
import org.apache.tapestry.services.ClassTransformation;
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockContribution.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockContribution.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockContribution.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockContribution.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,77 @@
+// 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.services;
+
+import org.apache.tapestry.corelib.components.Label;
+
+import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
+
+/**
+ * A contribution to the {@link BeanBlockSource} service, defining a page name and block id (within
+ * the page) that can edit or display a particular type of property.
+ */
+public final class BeanBlockContribution
+{
+ private final String _dataType;
+
+ private final String _pageName;
+
+ private final String _blockId;
+
+ private final boolean _edit;
+
+ public BeanBlockContribution(String dataType, String pageName, String blockId, boolean edit)
+ {
+ notBlank(dataType, "datatype");
+ notBlank(pageName, "pageName");
+ notBlank(blockId, "blockId");
+
+ _dataType = dataType;
+ _pageName = pageName;
+ _blockId = blockId;
+ _edit = edit;
+ }
+
+ /**
+ * The type of data for which the indicated block will provide an editor or displayer for.
+ */
+ public String getDataType()
+ {
+ return _dataType;
+ }
+
+ /** The id of the block within the page. */
+ public String getBlockId()
+ {
+ return _blockId;
+ }
+
+ /**
+ * If true, then the block provides an editor for the property, consisting of a {@link Label}
+ * and some field component (or set of field components). If false, the block is used to display
+ * the value of the property, usually by applying some kind of formatting to the raw value.
+ */
+ public boolean isEdit()
+ {
+ return _edit;
+ }
+
+ /** The logical name of the page containing the block. */
+ public String getPageName()
+ {
+ return _pageName;
+ }
+
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockSource.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockSource.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/BeanBlockSource.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,61 @@
+// 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.services;
+
+import org.apache.tapestry.Block;
+import org.apache.tapestry.corelib.components.BeanEditForm;
+import org.apache.tapestry.corelib.components.Grid;
+
+/**
+ * A source of {@link Block}s used to display the properties of a bean (used by the {@link Grid}
+ * component), or to edit the properties of a bean (used by the {@link BeanEditForm} component).
+ * Contributions to this service define what properties may be editted.
+ *
+ * @see DataTypeAnalyzer
+ */
+public interface BeanBlockSource
+{
+ /**
+ * Returns a block which can be used to present an editor for the given data type, in the form
+ * of a field label and input field.
+ *
+ * @param datatype
+ * logical name for the type of data to be displayed
+ * @return the Block
+ * @throws RuntimeException
+ * if no appropriate block is available
+ */
+ Block getEditBlock(String datatype);
+
+ /**
+ * Returns a block which can be used to present an output for the given data type.
+ *
+ * @param datatype
+ * logical name for the type of data to be displayed
+ * @return the Block
+ * @throws RuntimeException
+ * if no appropriate block is available
+ */
+ Block getDisplayBlock(String datatype);
+
+ /**
+ * Checks to see if there is a display block for the indicated data type.
+ *
+ * @param datatype
+ * to check for
+ * @return true if a block is available
+ */
+ boolean hasDisplayBlock(String datatype);
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/DataTypeAnalyzer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/DataTypeAnalyzer.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/DataTypeAnalyzer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/DataTypeAnalyzer.java Mon Jun 4 10:36:38 2007
@@ -22,11 +22,12 @@
* Used by {@link BeanModelSource} to identify the type of data associated with a particular
* property (represented as a {@link PropertyAdapter}). The data type is a string used to determine
* what kind of interface to use for displaying the value of the property, or what kind of interface
- * to use for editting the value of the property. Command property types are "text", "enum",
+ * to use for editting the value of the property. Common property types are "text", "enum",
* "checkbox", but the list is extensible.
*
* @see Grid
* @see BeanEditForm
+ * @see BeanBlockSource
*/
public interface DataTypeAnalyzer
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java Mon Jun 4 10:36:38 2007
@@ -27,6 +27,18 @@
*/
public interface FieldValidatorDefaultSource
{
+ /**
+ * Analyzes the property type and property annotations to determine the default set of
+ * validations for the property, which are wrapped to form a {@link FieldValidator} for a field.
+ *
+ * @param field
+ * @param overrideId
+ * @param overrideMessages
+ * @param locale
+ * @param propertyType
+ * @param propertyAnnotations
+ * @return
+ */
FieldValidator createDefaultValidator(Field field, String overrideId,
Messages overrideMessages, Locale locale, Class propertyType,
AnnotationProvider propertyAnnotations);
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyDisplayContext.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyDisplayContext.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyDisplayContext.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyDisplayContext.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,38 @@
+// 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.services;
+
+import org.apache.tapestry.corelib.components.Grid;
+import org.apache.tapestry.corelib.components.GridCell;
+import org.apache.tapestry.ioc.Messages;
+
+/**
+ * Provides context information needed when displaying a value in the context of a {@link Grid}
+ * component (or, really, the {@link GridCell} component).
+ */
+public interface PropertyDisplayContext
+{
+ /**
+ * Returns the value of the property (the object being displayed is encapsulated by the
+ * context).
+ */
+ Object getPropertyValue();
+
+ /**
+ * Returns the message catalog appropriate for use. In practice, this is the message catalog of
+ * the container of the {@link Grid} component.
+ */
+ Messages getContainerMessages();
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,86 @@
+// 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.services;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.Translator;
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.beaneditor.Validate;
+import org.apache.tapestry.corelib.components.BeanEditForm;
+import org.apache.tapestry.corelib.components.Label;
+import org.apache.tapestry.ioc.Messages;
+
+/**
+ * Defines a context for editting a property of a bean via {@link BeanEditForm}. This value is made
+ * available to blocks via the {@link Environmental} annotation.
+ *
+ * @see BeanBlockSource
+ */
+public interface PropertyEditContext
+{
+ /**
+ * Returns the current value of the property being editted (the context encapsulates the object
+ * containing the property).
+ */
+ Object getPropertyValue();
+
+ /**
+ * Updates the value of the property being editted (the context encapsulates the object
+ * containing the property).
+ *
+ * @param value
+ * new value for the property
+ */
+ void setPropertyValue(Object value);
+
+ /**
+ * Returns the user-presentable label, for use with the {@link Label} component, or to be
+ * integrated into any validation error messages.
+ */
+ String getLabel();
+
+ /**
+ * Returns the translator appropriate for the field (this is based on the property type).
+ *
+ * @see TranslatorDefaultSource
+ */
+ Translator getTranslator();
+
+ /**
+ * Returns the FieldValidator for the field.
+ *
+ * @see Validate
+ * @see FieldValidatorDefaultSource
+ */
+ FieldValidator getValidator(Field field);
+
+ /**
+ * Returns a string that identifies the property, usually the property name. This is used as the
+ * basis for the client-side client id.
+ */
+ String getPropertyId();
+
+ /**
+ * Returns the type of the property being editted.
+ */
+ Class getPropertyType();
+
+ /**
+ * Returns the message catalog for the container of the {@link BeanEditForm}, which is the
+ * correct place to look for strings used for labels, etc.
+ */
+ Messages getContainerMessages();
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Mon Jun 4 10:36:38 2007
@@ -77,6 +77,7 @@
import org.apache.tapestry.internal.services.AssetDispatcher;
import org.apache.tapestry.internal.services.AssetInjectionProvider;
import org.apache.tapestry.internal.services.AssetSourceImpl;
+import org.apache.tapestry.internal.services.BeanBlockSourceImpl;
import org.apache.tapestry.internal.services.BeanModelSourceImpl;
import org.apache.tapestry.internal.services.BindingSourceImpl;
import org.apache.tapestry.internal.services.ClasspathAssetAliasManagerImpl;
@@ -224,6 +225,7 @@
binder.bind(EnvironmentalShadowBuilder.class, EnvironmentalShadowBuilderImpl.class);
binder.bind(ComponentSource.class, ComponentSourceImpl.class);
binder.bind(BeanModelSource.class, BeanModelSourceImpl.class);
+ binder.bind(BeanBlockSource.class, BeanBlockSourceImpl.class);
}
public static MarkupWriterFactory build(final ComponentInvocationMap componentInvocationMap)
@@ -533,6 +535,28 @@
configuration.add(Number.class, "text");
configuration.add(Enum.class, "enum");
configuration.add(Boolean.class, "checkbox");
+ }
+
+ public static void contributeBeanBlockSource(Configuration<BeanBlockContribution> configuration)
+ {
+ addEditBlock(configuration, "text", "text");
+ addEditBlock(configuration, "enum", "enum");
+ addEditBlock(configuration, "checkbox", "checkbox");
+
+ addDisplayBlock(configuration, "enum", "enum");
+ }
+
+ private static void addEditBlock(Configuration<BeanBlockContribution> configuration,
+ String dataType, String blockId)
+ {
+ configuration.add(new BeanBlockContribution(dataType, "PropertyEditBlocks", blockId, true));
+ }
+
+ private static void addDisplayBlock(Configuration<BeanBlockContribution> configuration,
+ String dataType, String blockId)
+ {
+ configuration.add(new BeanBlockContribution(dataType, "PropertyDisplayBlocks", blockId,
+ false));
}
/**
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java Mon Jun 4 10:36:38 2007
@@ -22,7 +22,7 @@
public class DoubleTranslator implements Translator<Double>
{
/**
- * Parses blank values to null, otherwise parses the client value to a long
+ * Parses blank values to null, otherwise parses the client value to a double
*
* @throws ValidationException
* if the clientValue can not be parsed
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html Mon Jun 4 10:36:38 2007
@@ -2,7 +2,7 @@
<t:errors/>
<div class="t-beaneditor">
- <div class="t-beaneditor-row" t:type="Loop" t:source="model.propertyNames"
+ <div class="t-beaneditor-row" t:type="loop" t:source="model.propertyNames"
t:value="propertyName">
<t:delegate to="blockForProperty"/>
</div>
@@ -10,19 +10,5 @@
<input type="submit" value="${submitLabel}"/>
</div>
</div>
-
- <t:block id="text">
- <label t:type="Label" for="textField"/>
- <input t:id="textField"/>
- </t:block>
- <t:block id="enum">
- <t:label for="select"/>
- <input t:id="select"/>
- </t:block>
-
- <t:block id="checkbox">
- <t:label for="checkboxField"/>
- <input t:id="checkboxField"/>
- </t:block>
</form>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.properties?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.properties Mon Jun 4 10:36:38 2007
@@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-no-editor=The BeanEditor component does not include an editor of type '%s' (for property '%s').
submit-label=Create/Update
+block-error=Unable to locate a block to edit property '%s' (with data type '%s') of object %s: %s
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridColumns.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridColumns.html?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridColumns.html (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/components/GridColumns.html Mon Jun 4 10:36:38 2007
@@ -1,10 +1,10 @@
<thead xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<tr>
- <th t:type="Loop" source="columnNames" value="columnName" volatile="true" class="prop:cellClass">
+ <th t:type="Loop" source="columnNames" value="columnName" volatile="true" class="${columnModel.id}-header">
<a t:id="sort">${columnModel.label}</a>
<t:if test="activeSortColumn">
<a t:id="sort2">
- <t:img src="icon" class="t-sort-icon" alt="prop:iconLabel"/>
+ <img src="${icon}" id="${columnModel.id}:sort" class="t-sort-icon" alt="${iconLabel}"/>
</a>
</t:if>
</th>
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.html?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.html (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyDisplayBlocks.html Mon Jun 4 10:36:38 2007
@@ -0,0 +1,7 @@
+<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <t:block id="enum">
+ ${convertedEnumValue}
+ </t:block>
+
+</div>
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyEditBlocks.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyEditBlocks.html?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyEditBlocks.html (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/PropertyEditBlocks.html Mon Jun 4 10:36:38 2007
@@ -0,0 +1,18 @@
+<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <t:block id="text">
+ <t:label for="textField"/>
+ <input t:id="textField"/>
+ </t:block>
+
+ <t:block id="enum">
+ <t:label for="select"/>
+ <input t:id="select"/>
+ </t:block>
+
+ <t:block id="checkbox">
+ <t:label for="checkboxField"/>
+ <input t:id="checkboxField"/>
+ </t:block>
+
+</div>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Mon Jun 4 10:36:38 2007
@@ -78,3 +78,5 @@
corrupt-client-state=Serialized client state was corrupted. \
This may indicate that too much state is being stored, which can cause the encoded string to be truncated by the client web browser.
unclosed-attribute-expression=Attribute expression '%s' is missing a closing brace.
+no-display-for-data-type=There is no defined way to display data of type '%s'. Make a contribution to the BeanBlockSource service for this type.
+no-edit-for-data-type=There is no defined way to edit data of type '%s'. Make a contribution to the BeanBlockSource service for this type.
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/beaneditform.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/beaneditform.apt?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/beaneditform.apt (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/beaneditform.apt Mon Jun 4 10:36:38 2007
@@ -0,0 +1,213 @@
+ ---
+ Using the BeanEditForm Component
+ ---
+
+Using the BeanEditForm Component
+
+ Tapestry includes a powerful component capable of generating a complete create/edit user interface for a typical JavaBean, BeanEditForm.
+
+ BeanEditForm analyzes the the properties of the bean, locating just those properties that are readable and writeable. It filters down
+ to properties whose type is mapped to a known editor (this is described in more detail below).
+
+ The default ordering for properties is in the order in which the <getter methods> for the properties are defined.
+ When a super-class defines edittable properties, those are ordered before sub-class properties.
+
+* Supported Types
+
+ The default set of property types supported by BeanEditForm:
+
+ * String: as a text field
+
+ * Number: as a text field
+
+ * Enum: as a drop-down list
+
+ * Boolean: as a checkbox
+
+ []
+
+ Resolving a property type to an editor type involves a search up the inheritance hiearchy: thus the super-type of Integer, Long, BigDecimal, etc. is
+ Number, which uses a text field for data entry.
+
+
+* Automatic Creation
+
+ When a page is rendered, the BeanEditForm component will read its object parameter as the JavaBean to edit (with the current properties
+ of the JavaBean becoming the defaults for the various fields). Likewise, when the form is submitted by the user, the object parameter
+ is read and its properties populated from the request.
+
+ If the object does not exist, it will be created as needed. The type is determined from the property type, which should be a specific type
+ in order for automatic creation to operate properly.
+
+* Implicit Object Binding
+
+ If the object parameter is not bound, then an implicit binding to a property of the containing component is made. The bound property will be
+ the BeanEditForm component's id, if such a property exists. Thus you may typically give the BeanEditForm component an id (that matches a property)
+ and not have to bind the object parameter.
+
+* Non-Visual Properties
+
+ In some cases, a property may be updatable and of a supported type for editting, but should not be presented to the user for editting: for example,
+ a property that holds the primary key of a database entity. In such a case, the
+ {{{../apidocs/org/apache/tapestry/beaneditor/NonVisual.html}NonVisual}} annotation may be applied to the property (either the getter
+ or the setter method).
+
+* Default Validation
+
+ Default validation for fields is primarly determined by property type.
+
+ If desired, additional validation may be specified using the
+ {{{../apidocs/org/apache/tapestry/beaneditor/Validate.html}Validate}} annotation.
+
+* Property ordering
+
+ By default, the order in which properties are presented is as defined above (order of the getter method).
+ The {{{../apidocs/org/apache/tapestry/beaneditor/Order.html}Order}} annotation may be used to modify the normal ordering.
+
+* Default Label
+
+ Tapestry will attempt to provide a reasonable default label for each field, based on the property name being editted. The property name
+ is capitalized, and spaces are added before case changes, thus property "name" becomes label "Name" and property "streetAddress" becomes label
+ "Street Adresss".
+
+ BeanEditForm also searches for a label for the field in the containing component's message catalog. The message key is the property name suffixed with "-label".
+ If such a label is found, it takes precendence.
+
+Property Editor Overrides
+
+ You may override the editor for any particular property, using the a block parameter to the BeanEditForm component.
+
+ An editor normally consists of a Label component and some form of field component (such as TextField or TextArea).
+
+ For example, you may want to selectively use a PasswordField component:
+
++---+
+ <t:beaneditform object="loginCredentials">
+ <t:parameter name="password">
+ <t:label for="password"/>
+ <t:passwordfield t:id="password" value="loginCredentials.password"/>
+ </t:parameter>
+ </t:beaneditform>
++---+
+
+ The other fields will render normally (using the built-in editors).
+
+Providing the BeanModel
+
+ The BeanEditForm component operates in terms of a {{{../apidocs/org/apache/tapestry/beaneditor/BeanModel.html}BeanModel}}, which describes
+ the properties, their presentation order, labels and so forth.
+
+ Normally, the BeanEditForm automatically creates the BeanModel as needed, based on the type of object bound to its object parameter.
+
+ Alternately, the BeanModel can be supplied as the model parameter. This can be useful if certain properties should be omitted, or the order
+ of the properties needs to be changed. The model can be created when the page is first loaded:
+
++---+
+public class MyPage
+{
+ @Inject
+ private BeanModelSource _beanModelSource;
+
+ @Inject
+ private ComponentResources _resources;
+
+ @Retain
+ private BeanModel _model;
+
+ private MyBean _bean;
+
+ void pageLoaded()
+ {
+ _model = _beanModelSource.create(MyBean.class, true, _resources);
+
+ // Make other changes to _model here.
+ }
+
+ public MyBean getBean() { return _bean; }
+
+ public void setBean(MyBean bean) { _bean = bean; }
+
+ public BeanModel getModel() { return _model; }
+}
++---+
+
+ And, in the component template, the built model can be passed to the BeanEditForm component explicitly:
+
++---+
+ <t:beaneditform object="bean" model="model"/>
++--+
+
+Adding New Property Editors
+
+ Adding a new property editor is a three step process.
+
+ First, decide on a logical name for the data type. For example, you may decide that the BigDecimal type will represent currency in your application, so name the data type "currency".
+
+ Next, you must make contributions to the
+ {{{../apidocs/org/apache/tapestry/services/DataTypeAnalyzer.html}DataTypeAnalyzer}} or
+ {{{../apidocs/org/apache/tapestry/services/DefaultDataTypeAnalyzer.html}DefaultDataTypeAnalyzer}} services to match properties to your new name.
+
+ DataTypeAnalyzer is a chain of command that can make match properties to data types based on property type or annotations on the property. In general,
+ DefaultDataTypeAnalyzer is used, as that only needs to consider property type. DefaultDataTypeAnalyzer matches property types to data types, based on a search up
+ the inheritance path.
+
++---+
+public static void contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class, String> configuration)
+{
+ configuration.put(BigDecimal.class, "currency");
+}
++---+
+
+ You must provide an editor for the "currency" data type. An editor is a block of a page of the application; this page is not normally rendered itself, but acts as a container for
+ one or more blocks.
+
++---+
+public class AppPropertyEditBlocks
+{
+ @Environmental
+ private PropertyEditContext _context;
+
+ @Component(parameters =
+ { "value=context.propertyValue", "label=prop:context.label",
+ "translate=prop:currencyTranslator", "validate=prop:currencyValidator",
+ "clientId=prop:context.propertyId" })
+ private TextField _currency;
+
+ public PropertyEditContext getContext() { return _context; }
+
+ public FieldValidator getCurrencyValidator()
+ {
+ return _context.getValidator(_currency);
+ }
+
+ public Translator getCurrencyTranslator()
+ {
+ return ...;
+ }
+}
++---+
+
+ The editor is a block inside the component template:
+
++---+
+ <t:block id="currency">
+ <t:label for="currency"/>
+ <t:textfield t:id="currency" size="10"/>
+ </t:block>
++--+
+
+ Finally, we tell the BeanEditForm component about the editor via a contribution to the
+ {{{../apidocs/org/apache/tapestry/services/BeanBlockSource.html}BeanBlockSource}} service:
+
++---+
+public static void contributeBeanBlockSource(Configuration<BeanBlockContribution> configuration)
+{
+ configuration.add(new BeanBlockContribution("currency", "AppPropertyEditBlocks", "currency", true));
+}
++--+
+
+ Now, when the BeanEditForm sees a property of type BigDecimal, it will map that to datatype "currency" and from there
+ to the currency block of the AppPropertyEditBlocks page of the application.
+
+
+
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/site.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/site.xml?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/site.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/site.xml Mon Jun 4 10:36:38 2007
@@ -63,6 +63,7 @@
<item name="Component Parameters" href="guide/parameters.html"/>
<item name="Page Navigation" href="guide/pagenav.html"/>
<item name="Input Validation" href="guide/validation.html"/>
+ <item name="BeanEditForm Guide" href="guide/beaneditform.html"/>
<item name="Component Events" href="guide/event.html"/>
<item name="Page Lifecycle" href="guide/lifecycle.html"/>
<item name="Component Mixins" href="guide/mixins.html"/>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/BeanEditorDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/BeanEditorDemo.html?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/BeanEditorDemo.html (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/BeanEditorDemo.html Mon Jun 4 10:36:38 2007
@@ -1,7 +1,7 @@
<t:border xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<h1>${pageTitle}</h1>
- <form t:id="edit" submitlabel="Register">
+ <form t:id="registrationData" submitlabel="Register">
<t:parameter name="firstName">
<t:label for="firstName"/>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/BeanEditFormTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/BeanEditFormTest.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/BeanEditFormTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/components/BeanEditFormTest.java Mon Jun 4 10:36:38 2007
@@ -14,12 +14,17 @@
package org.apache.tapestry.corelib.components;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isA;
+
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.beaneditor.BeanModel;
import org.apache.tapestry.integration.app1.data.RegistrationData;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.internal.util.TapestryException;
+import org.apache.tapestry.services.PropertyEditContext;
import org.apache.tapestry.services.BeanModelSource;
+import org.apache.tapestry.services.Environment;
import org.apache.tapestry.test.TapestryTestCase;
import org.testng.annotations.Test;
@@ -32,9 +37,12 @@
ComponentResources containerResources = mockComponentResources();
BeanModelSource source = mockBeanModelSource();
BeanModel model = mockBeanModel();
+ Environment environment = mockEnvironment();
expect(resources.triggerEvent(Form.PREPARE, null, null)).andReturn(false);
+ train_push(environment, PropertyEditContext.class);
+
train_getBoundType(resources, RegistrationData.class);
train_getContainerResources(resources, containerResources);
@@ -45,7 +53,7 @@
BeanEditForm component = new BeanEditForm();
- component.inject(resources, source);
+ component.inject(resources, source, environment);
assertTrue(component.onPrepareFromForm());
@@ -62,9 +70,12 @@
{
ComponentResources resources = mockComponentResources();
Location l = mockLocation();
+ Environment environment = mockEnvironment();
expect(resources.triggerEvent(Form.PREPARE, null, null)).andReturn(false);
+ train_push(environment, PropertyEditContext.class);
+
train_getBoundType(resources, Runnable.class);
train_getCompleteId(resources, "Foo.bar");
@@ -75,7 +86,7 @@
BeanEditForm component = new BeanEditForm();
- component.inject(resources, null);
+ component.inject(resources, null, environment);
try
{
@@ -91,5 +102,10 @@
}
verify();
+ }
+
+ protected final <T> void train_push(Environment environment, Class<T> type)
+ {
+ expect(environment.push(eq(type), isA(type))).andReturn(null);
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Mon Jun 4 10:36:38 2007
@@ -40,14 +40,14 @@
open(BASE_URL);
clickAndWait("link=AssetDemo");
- assertText("//img[@id='img']/@src", "/images/tapestry_banner.gif");
+ assertText("//img[@id='icon']/@src", "/images/tapestry_banner.gif");
// This doesn't prove that the image shows up in the client browser (it does, but
// it could just as easily be a broken image). Haven't figured out how Selenium
// allows this to be verified. Note that the path below represents some aliasing
// of the raw classpath resource path.
- assertText("//img[@id='img_0']/@src", "/assets/app1/pages/tapestry-button.png");
+ assertText("//img[@id='button']/@src", "/assets/app1/pages/tapestry-button.png");
// Read the byte stream for the asset and compare to the real copy.
@@ -655,8 +655,8 @@
clickAndWait("link=Rating");
- assertText("//img[@id='img']/@src", "/assets/tapestry/corelib/components/sort-asc.png");
- assertText("//img[@id='img']/@alt", "[Asc]");
+ assertText("//img[@id='rating:sort']/@src", "/assets/tapestry/corelib/components/sort-asc.png");
+ assertText("//img[@id='rating:sort']/@alt", "[Asc]");
assertTextSeries(
"//tr[22]/td[%d]",
@@ -672,15 +672,15 @@
clickAndWait("link=Rating");
- assertText("//img[@id='img']/@src", "/assets/tapestry/corelib/components/sort-desc.png");
- assertText("//img[@id='img']/@alt", "[Desc]");
+ assertText("//img[@id='rating:sort']/@src", "/assets/tapestry/corelib/components/sort-desc.png");
+ assertText("//img[@id='rating:sort']/@alt", "[Desc]");
assertTextSeries("//tr[1]/td[%d]", 1, "Hey Blondie", "Out from Out Where");
clickAndWait("link=Title");
- assertText("//img[@id='img']/@src", "/assets/tapestry/corelib/components/sort-asc.png");
- assertText("//img[@id='img']/@alt", "[Asc]");
+ assertText("//img[@id='title:sort']/@src", "/assets/tapestry/corelib/components/sort-asc.png");
+ assertText("//img[@id='title:sort']/@alt", "[Asc]");
clickAndWait("link=1");
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/ProgrammingLanguage.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/ProgrammingLanguage.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/ProgrammingLanguage.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/ProgrammingLanguage.java Mon Jun 4 10:36:38 2007
@@ -4,7 +4,7 @@
// 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,
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java Mon Jun 4 10:36:38 2007
@@ -21,9 +21,9 @@
public class BeanEditorDemo
{
- @Component(parameters =
- { "clientValidation=clientValidation", "object=registrationData" })
- private BeanEditForm _edit;
+ @Component(id = "registrationData", parameters =
+ { "clientValidation=clientValidation" })
+ private BeanEditForm _form;
@ApplicationState
private RegistrationData _data;
@@ -41,7 +41,7 @@
void onActionFromClear()
{
_data = null;
- _edit.clearErrors();
+ _form.clearErrors();
}
public boolean getClientValidation()
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanBlockSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanBlockSourceImplTest.java?view=auto&rev=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanBlockSourceImplTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanBlockSourceImplTest.java Mon Jun 4 10:36:38 2007
@@ -0,0 +1,140 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
+
+import java.util.Collection;
+
+import org.apache.tapestry.Block;
+import org.apache.tapestry.internal.structure.ComponentPageElement;
+import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.services.BeanBlockContribution;
+import org.apache.tapestry.services.BeanBlockSource;
+import org.testng.annotations.Test;
+
+public class BeanBlockSourceImplTest extends InternalBaseTestCase
+{
+ @Test
+ public void found_display_block()
+ {
+ Block block = mockBlock();
+ RequestPageCache cache = mockRequestPageCache();
+ Page page = mockPage();
+ BeanBlockContribution contribution = new BeanBlockContribution("mydata", "MyPage",
+ "mydisplay", false);
+ Collection<BeanBlockContribution> configuration = newList(contribution);
+
+ train_get(cache, "MyPage", page);
+ train_getBlock(page, "mydisplay", block);
+
+ replay();
+
+ BeanBlockSource source = new BeanBlockSourceImpl(cache, configuration);
+
+ // Check case insensitivity while we are at it.
+ assertTrue(source.hasDisplayBlock("MyData"));
+ Block actual = source.getDisplayBlock("MyData");
+
+ assertSame(actual, block);
+
+ verify();
+ }
+
+ @Test
+ public void display_block_not_found()
+ {
+ RequestPageCache cache = mockRequestPageCache();
+ Collection<BeanBlockContribution> configuration = newList();
+
+ replay();
+
+ BeanBlockSource source = new BeanBlockSourceImpl(cache, configuration);
+
+ try
+ {
+ assertFalse(source.hasDisplayBlock("MyData"));
+ source.getDisplayBlock("MyData");
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertEquals(
+ ex.getMessage(),
+ "There is no defined way to display data of type \'MyData\'. Make a contribution to the BeanBlockSource service for this type.");
+ }
+
+ verify();
+ }
+
+ @Test
+ public void edit_block_not_found()
+ {
+ RequestPageCache cache = mockRequestPageCache();
+ Collection<BeanBlockContribution> configuration = newList();
+
+ replay();
+
+ BeanBlockSource source = new BeanBlockSourceImpl(cache, configuration);
+
+ try
+ {
+ source.getEditBlock("MyData");
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertEquals(
+ ex.getMessage(),
+ "There is no defined way to edit data of type \'MyData\'. Make a contribution to the BeanBlockSource service for this type.");
+ }
+
+ verify();
+ }
+
+ @Test
+ public void found_edit_block()
+ {
+ Block block = mockBlock();
+ RequestPageCache cache = mockRequestPageCache();
+ Page page = mockPage();
+ BeanBlockContribution contribution = new BeanBlockContribution("mydata", "MyPage",
+ "mydisplay", true);
+ Collection<BeanBlockContribution> configuration = newList(contribution);
+
+ train_get(cache, "MyPage", page);
+ train_getBlock(page, "mydisplay", block);
+
+ replay();
+
+ BeanBlockSource source = new BeanBlockSourceImpl(cache, configuration);
+
+ // Check case insensitivity while we are at it.
+ Block actual = source.getEditBlock("MyData");
+
+ assertSame(actual, block);
+
+ verify();
+ }
+
+ protected final void train_getBlock(Page page, String blockId, Block block)
+ {
+ ComponentPageElement element = mockComponentPageElement();
+ train_getRootElement(page, element);
+
+ expect(element.getBlock(blockId)).andReturn(block);
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html?view=diff&rev=544192&r1=544191&r2=544192
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/integration/app1/pages/AssetDemo.html Mon Jun 4 10:36:38 2007
@@ -8,12 +8,12 @@
The Tapestry banner:
</p>
- <t:img src="icon"/>
+ <img id="icon" src="${icon}"/>
<p>
A classpath asset:
</p>
- <t:img src="button"/>
+ <img id="button" src="${button}"/>
</html>