You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/02/06 22:17:10 UTC
svn commit: r504296 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/
main/java/org/apache/tapestry/corelib/components/
main/java/org/apache/tapestry/internal/structure/ test/app1/WEB-INF/
test/java/org/apache/tapestry/in...
Author: hlship
Date: Tue Feb 6 13:17:10 2007
New Revision: 504296
URL: http://svn.apache.org/viewvc?view=rev&rev=504296
Log:
Change BeanEditForm to support the passing of Block parameters to override specific properties within the editor.
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.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/internal/structure/InternalComponentResourcesImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java Tue Feb 6 13:17:10 2007
@@ -108,4 +108,13 @@
* @return the annotation provider, or null if the parameter is not bound
*/
AnnotationProvider getAnnotationProvider(String parameterName);
+
+ /**
+ * Used to access an informal parameter that's a Block.
+ *
+ * @param parameterName
+ * the name of the informal parameter (case is ignored)
+ * @return the informal Block parameter, or null if not bound
+ */
+ Block getBlockParameter(String parameterName);
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java Tue Feb 6 13:17:10 2007
@@ -133,4 +133,6 @@
* if no block with the given id exists
*/
Block getBlock(String blockId);
+
+
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java Tue Feb 6 13:17:10 2007
@@ -29,6 +29,7 @@
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.annotations.SupportsInformalParameters;
import org.apache.tapestry.beaneditor.BeanEditorModel;
import org.apache.tapestry.beaneditor.PropertyEditModel;
import org.apache.tapestry.ioc.Messages;
@@ -44,6 +45,11 @@
* field, checkbox, drop down list) determined from the property type, and the order and validation
* for the properties determined from annotations on the property's getter and setter methods.
* <p>
+ * You may add <t:parameter>s to the component; when the name matches (case insensitive) the name of
+ * a property, then the corresponding Block is renderered, rather than any of the built in property
+ * editor blocks. This allows you to override specific properties with your own customized UI, for
+ * cases where the default UI is insufficient, or no built-in editor type is appropriate.
+ * <p>
* This component is likely to change more than any other thing in Tapestry! What's available now is
* a very limited preview of its eventual functionality.
*
@@ -51,6 +57,7 @@
* @see BeanEditorModelSource
*/
@ComponentClass
+@SupportsInformalParameters
public class BeanEditForm
{
/** The object to be editted by the BeanEditor. */
@@ -128,12 +135,22 @@
public void setPropertyName(String propertyName)
{
+ _propertyName = propertyName;
+
_propertyEditModel = _model.get(propertyName);
_blockForProperty = null;
_fieldForProperty = null;
- _propertyName = propertyName;
+ String overrideName = propertyName.replace(".", "");
+
+ Block override = _resources.getBlockParameter(overrideName);
+
+ if (override != null)
+ {
+ _blockForProperty = override;
+ return;
+ }
String editorType = _propertyEditModel.getEditorType();
@@ -202,11 +219,6 @@
public Block getBlockForProperty()
{
return _blockForProperty;
- }
-
- public Field getFieldForProperty()
- {
- return _fieldForProperty;
}
public Object getValueForProperty()
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java Tue Feb 6 13:17:10 2007
@@ -254,10 +254,27 @@
for (String name : _bindings.keySet())
{
+ // Skip all formal parameters.
+
if (_componentModel.getParameterModel(name) != null)
continue;
- writer.attributes(name, readParameter(name, String.class));
+ Binding b = _bindings.get(name);
+
+ Object value = b.get();
+
+ if (value == null)
+ continue;
+
+ // Because Blocks can be passed in (right from the template, using <t:parameter>,
+ // we want to skip those when rending informal parameters.
+
+ if (value instanceof Block)
+ continue;
+
+ String valueString = _typeCoercer.coerce(value, String.class);
+
+ writer.attributes(name, valueString);
}
}
@@ -310,4 +327,18 @@
{
return _element.getBlock(blockId);
}
+
+ public Block getBlockParameter(String parameterName)
+ {
+ if (_bindings == null)
+ return null;
+
+ String key = parameterName.toLowerCase();
+
+ if (_bindings.containsKey(key))
+ return (Block) _bindings.get(key).get();
+
+ return null;
+ }
+
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html Tue Feb 6 13:17:10 2007
@@ -1,7 +1,14 @@
<t:comp type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<h1>BeanEditor Component Demo</h1>
- <t:comp id="edit" object="registrationData"/>
+ <t:comp id="edit" object="registrationData">
+
+ <t:parameter name="firstName">
+ <label t:type="Label" for="firstName"/>
+ <input t:type="TextField" t:id="firstName" value="registrationData.firstName" size="40"/> (First Name is Required)
+ </t:parameter>
+
+ </t:comp>
<p>
[<a t:type="ActionLink" t:id="clear">Clear Data</a>]
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=504296&r1=504295&r2=504296
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Tue Feb 6 13:17:10 2007
@@ -715,10 +715,13 @@
clickAndWait(submitButton);
assertTextPresent(
+ "(First Name is Required)",
"You must provide a value for First Name.",
"Everyone has to have a last name!",
"Year of Birth requires a value of at least 1900.");
+ assertText("//input[@id='firstName']/@size", "40");
+
_selenium.type("firstName", "a");
_selenium.type("lastName", "b");
_selenium.type("birthYear", "");