Author: hlship
Date: Wed Feb 28 15:29:38 2007
New Revision: 513061
URL: http://svn.apache.org/viewvc?view=rev&rev=513061
Log:
TAPESTRY-1302: Build simple but effective client-side JavaScript input
validation on top of Scriptaculous.
Always write an icon next to each field, but mark it as invisible if the field
is not in error. Icons have an id attribute of the field's id appended with
":icon".
Always write an id attribute for each field, with the id consisting of the
field's id appended with ":label".
Change the Errors component to always output the <div>, marking it invisible if
there is no validation errors. The <div>'s id is the id of the enclosing form
appended with ":errors".
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/field-error-marker.png
(with props)
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Errors.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.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/internal/DefaultValidationDecorator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/DefaultValidationDelegateCommand.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FormSupport.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/SimpleForm.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DefaultValidationDecoratorTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Errors.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Errors.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Errors.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Errors.java
Wed Feb 28 15:29:38 2007
@@ -19,6 +19,7 @@
import org.apache.tapestry.annotations.Environmental;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.internal.InternalConstants;
+import org.apache.tapestry.services.FormSupport;
/**
* Standard validation error presenter. Must be enclosed by a [EMAIL
PROTECTED] Form} component. If errors are
@@ -42,6 +43,9 @@
@Environmental(false)
private ValidationTracker _tracker;
+ @Environmental
+ private FormSupport _formSupport;
+
void beginRender(MarkupWriter writer)
{
// TODO: Would be nice if there was a Location to report ... can we
add a Location property
@@ -50,10 +54,9 @@
if (_tracker == null)
throw new
RuntimeException(ComponentMessages.encloseErrorsInForm());
- if (!_tracker.getHasErrors())
- return;
+ String cssClass = _tracker.getHasErrors() ? _class : _class + "
t-invisible";
- writer.element("div", "class", _class);
+ writer.element("div", "class", cssClass, "id",
_formSupport.getClientId() + ":errors");
// Inner div for the banner text
writer.element("div");
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
Wed Feb 28 15:29:38 2007
@@ -191,8 +191,9 @@
_defaultTracker = defaultTracker;
}
- void setupRender()
+ void beginRender(MarkupWriter writer)
{
+
try
{
_actions = new Base64ObjectOutputStream();
@@ -202,26 +203,21 @@
throw new RuntimeException(ex);
}
- _formSupport = new FormSupportImpl(_actions);
+ _name = _pageRenderSupport.allocateClientId(_resources.getId());
+
+ _formSupport = new FormSupportImpl(_name, _actions);
// TODO: Forms should not allow to nest. Perhaps a set() method
instead of a push() method
// for this kind of check?
_environment.push(FormSupport.class, _formSupport);
_environment.push(ValidationTracker.class, _tracker);
-
- }
-
- void beginRender(MarkupWriter writer)
- {
// Now that the environment is setup, inform the component or other
listeners that the form
// is about to render.
Object[] contextArray = _context == null ? new Object[0] :
_context.toArray();
_resources.triggerEvent(PREPARE, contextArray, null);
-
- _name = _pageRenderSupport.allocateClientId(_resources.getId());
Link link =
_resources.createActionLink(TapestryConstants.ACTION_EVENT, true, contextArray);
writer.element("form", "name", _name, "id", _name, "method", "post",
"action", link);
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/FormSupportImpl.java
Wed Feb 28 15:29:38 2007
@@ -39,6 +39,8 @@
{
private final IdAllocator _idAllocator = new IdAllocator();
+ private final String _clientId;
+
private final ObjectOutputStream _actions;
private final FormParameterLookup _parameterLookup;
@@ -48,23 +50,24 @@
/** Constructor used when processing a form submission. */
public FormSupportImpl(FormParameterLookup parameterLookup)
{
- this(null, parameterLookup);
+ this(null, null, parameterLookup);
}
/** Constructor used when rendering. */
- public FormSupportImpl(ObjectOutputStream actions)
+ public FormSupportImpl(String clientId, ObjectOutputStream actions)
{
- this(actions, null);
+ this(clientId, actions, null);
}
/** For testing only. */
FormSupportImpl()
{
- this(null, null);
+ this(null, null, null);
}
- FormSupportImpl(ObjectOutputStream actions, FormParameterLookup
parameterLookup)
+ FormSupportImpl(String clientId, ObjectOutputStream actions,
FormParameterLookup parameterLookup)
{
+ _clientId = clientId;
_actions = actions;
_parameterLookup = parameterLookup;
}
@@ -127,4 +130,8 @@
return _parameterLookup.getParameter(name);
}
+ public String getClientId()
+ {
+ return _clientId;
+ }
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java
Wed Feb 28 15:29:38 2007
@@ -75,7 +75,7 @@
{
String fieldId = field.getClientId();
- element.forceAttributes("for", fieldId);
+ element.forceAttributes("for", fieldId, "id", fieldId +
":label");
decorator.insideLabel(field, element);
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/DefaultValidationDecorator.java
Wed Feb 28 15:29:38 2007
@@ -14,12 +14,15 @@
package org.apache.tapestry.internal;
+import org.apache.tapestry.Asset;
import org.apache.tapestry.BaseValidationDecorator;
import org.apache.tapestry.Field;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.ValidationTracker;
import org.apache.tapestry.dom.Element;
+import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.services.Environment;
+import org.apache.tapestry.services.ValidationMessagesSource;
/**
* Default implementation that writes an attribute into fields or labels that
are in error.
@@ -28,9 +31,26 @@
{
private final Environment _environment;
- public DefaultValidationDecorator(final Environment environment)
+ private Asset _iconAsset;
+
+ private Messages _validationMessages;
+
+ /**
+ * @param environment
+ * used to locate objects and services during the render
+ * @param validationMessages
+ * obtained from [EMAIL PROTECTED] ValidationMessagesSource},
used to obtain the label for the
+ * icon
+ * @param iconAsset
+ * asset for an icon that will be displayed after each field
(marked with the
+ * "t-invisible" CSS class, if the field is not in error)
+ */
+ public DefaultValidationDecorator(final Environment environment, Messages
validationMessages,
+ Asset iconAsset)
{
_environment = environment;
+ _validationMessages = validationMessages;
+ _iconAsset = iconAsset;
}
@Override
@@ -48,6 +68,20 @@
if (inError(field))
addErrorClass(element);
+ }
+
+ @Override
+ public void afterField(Field field)
+ {
+ String iconId = field.getClientId() + ":icon";
+
+ MarkupWriter writer = _environment.peekRequired(MarkupWriter.class);
+
+ String cssClass = inError(field) ? "t-error-icon" : "t-error-icon
t-invisible";
+
+ writer.element("img", "src", _iconAsset.toClientURL(), "alt",
_validationMessages
+ .get("icon-label"), "class", cssClass, "id", iconId);
+ writer.end();
}
private boolean inError(Field field)
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/DefaultValidationDelegateCommand.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/DefaultValidationDelegateCommand.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/DefaultValidationDelegateCommand.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/DefaultValidationDelegateCommand.java
Wed Feb 28 15:29:38 2007
@@ -14,10 +14,14 @@
package org.apache.tapestry.internal.services;
+import org.apache.tapestry.Asset;
import org.apache.tapestry.ValidationDecorator;
import org.apache.tapestry.internal.DefaultValidationDecorator;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.services.Environment;
import org.apache.tapestry.services.PageRenderCommand;
+import org.apache.tapestry.services.ValidationMessagesSource;
/**
* Pushes a [EMAIL PROTECTED] DefaultValidationDecorator} instance into the
Environment's
@@ -25,6 +29,20 @@
*/
public class DefaultValidationDelegateCommand implements PageRenderCommand
{
+ private final ThreadLocale _threadLocale;
+
+ private final ValidationMessagesSource _messagesSource;
+
+ private final Asset _iconAsset;
+
+ public DefaultValidationDelegateCommand(ThreadLocale threadLocale,
+ ValidationMessagesSource messagesSource, Asset iconAsset)
+ {
+ _threadLocale = threadLocale;
+ _messagesSource = messagesSource;
+ _iconAsset = iconAsset;
+ }
+
public void cleanup(Environment environment)
{
environment.pop(ValidationDecorator.class);
@@ -32,7 +50,10 @@
public void setup(Environment environment)
{
- ValidationDecorator decorator = new
DefaultValidationDecorator(environment);
+ Messages messages =
_messagesSource.getValidationMessages(_threadLocale.getLocale());
+
+ ValidationDecorator decorator = new
DefaultValidationDecorator(environment, messages,
+ _iconAsset);
environment.push(ValidationDecorator.class, decorator);
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FormSupport.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FormSupport.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FormSupport.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FormSupport.java
Wed Feb 28 15:29:38 2007
@@ -14,6 +14,7 @@
package org.apache.tapestry.services;
+import org.apache.tapestry.ClientElement;
import org.apache.tapestry.ComponentAction;
import org.apache.tapestry.test.pagelevel.PageTester;
@@ -23,7 +24,7 @@
*
* @author Howard M. Lewis Ship
*/
-public interface FormSupport
+public interface FormSupport extends ClientElement
{
/**
* Allocates a unique (within the form) element name for some component
enclosed component,
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
Wed Feb 28 15:29:38 2007
@@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
@@ -26,6 +27,7 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
+import org.apache.tapestry.Asset;
import org.apache.tapestry.Link;
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.PageRenderSupport;
@@ -963,7 +965,7 @@
};
}
- public static void contributePageRenderInitializer(
+ public void contributePageRenderInitializer(
OrderedConfiguration<PageRenderCommand> configuration,
@InjectService("tapestry.ioc.ThreadLocale")
@@ -972,6 +974,9 @@
@Inject("infrastructure:AssetSource")
AssetSource assetSource,
+ @Inject("infrastructure:ValidationMessagesSource")
+ ValidationMessagesSource validationMessagesSource,
+
@Inject("service:tapestry.ioc.SymbolSource")
final SymbolSource symbolSource,
@@ -1020,7 +1025,13 @@
configuration.add("InjectStandardStylesheet", new
InjectStandardStylesheetCommand(
threadLocale, assetSource));
- configuration.add("DefaultValidationDelegate", new
DefaultValidationDelegateCommand());
+
+ Asset iconAsset = assetSource.getClasspathAsset(
+ "org/apache/tapestry/field-error-marker.png",
+ Locale.ENGLISH);
+
+ configuration.add("DefaultValidationDelegate", new
DefaultValidationDelegateCommand(
+ threadLocale, validationMessagesSource, iconAsset));
}
/** A public service since extensions may provide new persistent
strategies. */
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
Wed Feb 28 15:29:38 2007
@@ -37,6 +37,11 @@
color: red;
}
+IMG.t-error-icon
+{
+ margin-left: 4px;
+}
+
DIV.t-exception-message
{
font-style: italic;
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/field-error-marker.png
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/field-error-marker.png?view=auto&rev=513061
==============================================================================
Binary file - no diff available.
Propchange:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/field-error-marker.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
Wed Feb 28 15:29:38 2007
@@ -26,3 +26,7 @@
integer-format-exception=The input value '%s' is not parseable as an integer
value.
number-format-exception=The input value '%s' is not parseable as a numeric
value.
+
+# The label/alt text for the icon that is displayed next to each field.
+
+icon-label=[Error]
\ No newline at end of file
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js
Wed Feb 28 15:29:38 2007
@@ -17,10 +17,29 @@
registerForm : function(form) {
form = $(form);
+ form.errorDiv = $(form.id + ':errors');
+
+ if (form.errorDiv) {
+ form.errorList = form.errorDiv.getElementsBySelector("UL").first();
+
+ Tapestry.hideInvisible(form.errorDiv);
+ }
+
+ // This can probably be cleaned up with bind() ...
+
form.onsubmit = function() {
var event = new Tapestry.FormEvent(form);
+
+ form.firstError = true;
- form.getElements().each(function (element) {
+ if (form.errorList) {
+ form.errorList.innerHTML = '';
+ }
+
+ // Locaate elements that have an event manager (and therefore,
validations)
+ // and let those validations execute, which may result in calls to
recordError().
+
+ form.getElements().each(function(element) {
if (element.fieldEventManager != undefined) {
event.field = element;
element.fieldEventManager.validateInput(event);
@@ -29,22 +48,51 @@
}
});
+// window.alert("result = " + event.result);
+
+ // On a failure result, display the error div.
+
+ if (form.errorDiv) {
+ if (event.result) {
+ if (form.errorDiv.visible())
+ new Effect.BlindUp(form.errorDiv);
+ }
+ else if (! form.errorDiv.visible()) {
+ new Effect.BlindDown(form.errorDiv);
+ }
+ }
+
return event.result;
};
-
- form.invalidField = function(field, event, message) {
-
- field = $(field);
- if (field.focus) field.focus();
- if (field.select) field.select();
+
+ form.recordError = function(field, event, message) {
+
+ if (form.firstError) {
+ field = $(field);
+ if (field.focus) field.focus();
+ if (field.select) field.select();
+
+ form.firstError = false;
+ }
- window.alert(message);
+ if (form.errorList)
+ new Insertion.Bottom(form.errorList, "<li>" + message + "</li>");
- // While we're still using the primitive popup system, we need to abort
the event
- // after displaying the alert.
- event.abort = true;
};
-
+ },
+
+ // Checks the element; if it has the "t-invisible" CSS class, then
+ // the element is hidden,and the t-invisible CSS class is removed. This is
necessary
+ // for Prototype's visible() method, which can't determine visibility when
it's defined via
+ // CSS.
+
+ hideInvisible : function(element) {
+ element = $(element);
+
+ if (element.classNames().include("t-invisible")) {
+ element.hide();
+ element.removeClassName("t-invisible");
+ }
},
FormEvent : Class.create(),
@@ -127,7 +175,7 @@
// true.
recordError : function(message) {
- this.form.invalidField(this.field, this, message);
+ this.form.recordError(this.field, this, message);
this.result = false;
this.error = true;
}
@@ -140,6 +188,13 @@
$(field).fieldEventManager = this;
this.validators = [ ];
+
+ var id = field.id;
+ this.label = $(id + ':label');
+ this.icon = $(id + ':icon');
+ if (this.icon)
+ Tapestry.hideInvisible(this.icon);
+
},
// Adds a validator. acceptBlank is true if the validator should be invoked
regardless of
@@ -158,6 +213,15 @@
// should not modify the field's value.
validateInput : function(event) {
+ // Clear out old decorations. It's easier to remove the decorations
+ // and then re-add them if the field is in error than it is to
+ // toggle them on or off at the end.
+
+ event.field.removeClassName("t-error");
+
+ if (this.label)
+ this.label.removeClassName("t-error");
+
var value = $F(event.field);
var isBlank = (value == '');
@@ -177,6 +241,23 @@
if (event.error) throw $break;
}
});
+
+ if (event.error) {
+ event.field.addClassName("t-error");
+
+ if (this.label)
+ this.label.addClassName("t-error");
+ }
+
+ if (this.icon) {
+ if (event.error && ! this.icon.visible()) {
+ new Effect.Appear(this.icon);
+ }
+ else if (! event.error && this.icon.visible()) {
+ this.icon.hide();
+ }
+ }
+
}
};
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/SimpleForm.html
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/SimpleForm.html?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/SimpleForm.html
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/SimpleForm.html
Wed Feb 28 15:29:38 2007
@@ -1,50 +1,47 @@
<t:comp type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <h1>Simple Form</h1>
+ <h1>Simple Form</h1>
- <p> This is the <em>very early</em> start to Tapestry 5 form support. </p>
+ <p> This is the <em>very early</em> start to Tapestry 5 form support. </p>
- <form t:type="Form">
- <input t:type="Checkbox" t:id="disabled"/>
- <label id="l1" t:type="Label" for="disabled"/>
- <br/>
-
- <div class="t-beaneditor">
-
- <label id="l2" t:type="Label" for="email">This isn't used</label>
- <input t:type="TextField"
- t:id="email" value="incident.email" size="50"
disabled="disabled"/>
- <br/>
- <label id="l3" t:type="Label" for="message"/>
- <input t:type="TextArea" t:id="message"
- label="Incident Message" value="incident.message" cols="50"
rows="10"
- disabled="disabled"> You can put text here, but it isn't used.
</input>
- <br/>
- <label id="l4" t:type="Label" for="operatingSystem"/>
- <select t:type="Select"
- t:id="operatingSystem" value="incident.operatingSystem"
model="message:os-values"
- disabled="disabled"/>
- <br/>
- <label id="l5" t:type="Label" for="department"/>
- <select t:type="Select" t:id="department"
- value="incident.department" disabled="disabled"/>
- <br/>
- <label id="l6" t:type="Label" for="urgent"/>
- <input t:type="Checkbox" t:id="urgent" value="incident.urgent"
disabled="disabled"/>
- <br/>
- <input type="submit"/></div>
- </form>
-
- <hr/>
-
- <p> Entered data: </p>
-
- <ul>
- <li>email: [${incident.email}]</li>
- <li>message: [${incident.message}]</li>
- <li>OS: [${incident.operatingSystem}]</li>
- <li>urgent: [${incident.urgent}]</li>
- <li>department: [${incident.department}]</li>
- </ul>
+ <form t:type="Form">
+ <input t:type="Checkbox" t:id="disabled"/>
+ <label t:type="Label" for="disabled"/>
+ <br/>
+
+ <div class="t-beaneditor">
+
+ <label t:type="Label" for="email">This isn't used</label>
+ <input t:type="TextField" t:id="email" value="incident.email" size="50"
disabled="disabled"/>
+ <br/>
+ <label t:type="Label" for="message"/>
+ <input t:type="TextArea" t:id="message" label="Incident Message"
value="incident.message"
+ cols="50" rows="10" disabled="disabled"> You can put text here, but it
isn't used. </input>
+ <br/>
+ <label t:type="Label" for="operatingSystem"/>
+ <select t:type="Select" t:id="operatingSystem"
value="incident.operatingSystem"
+ model="message:os-values" disabled="disabled"/>
+ <br/>
+ <label t:type="Label" for="department"/>
+ <select t:type="Select" t:id="department" value="incident.department"
disabled="disabled"/>
+ <br/>
+ <label t:type="Label" for="urgent"/>
+ <input t:type="Checkbox" t:id="urgent" value="incident.urgent"
disabled="disabled"/>
+ <br/>
+ <input type="submit"/>
+ </div>
+ </form>
+
+ <hr/>
+
+ <p> Entered data: </p>
+
+ <ul>
+ <li>email: [${incident.email}]</li>
+ <li>message: [${incident.message}]</li>
+ <li>OS: [${incident.operatingSystem}]</li>
+ <li>urgent: [${incident.urgent}]</li>
+ <li>department: [${incident.department}]</li>
+ </ul>
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=513061&r1=513060&r2=513061
==============================================================================
---
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
Wed Feb 28 15:29:38 2007
@@ -454,12 +454,12 @@
clickAndWait("link=SimpleForm");
- assertText("//[EMAIL PROTECTED]'l1']", "Disabled");
- assertText("//[EMAIL PROTECTED]'l2']", "Email");
- assertText("//[EMAIL PROTECTED]'l3']", "Incident Message");
- assertText("//[EMAIL PROTECTED]'l4']", "Operating System");
- assertText("//[EMAIL PROTECTED]'l5']", "Department");
- assertText("//[EMAIL PROTECTED]'l6']", "Urgent Processing Requested");
+ assertText("//[EMAIL PROTECTED]'disabled:label']", "Disabled");
+ assertText("//[EMAIL PROTECTED]'email:label']", "Email");
+ assertText("//[EMAIL PROTECTED]'message:label']", "Incident Message");
+ assertText("//[EMAIL PROTECTED]'operatingSystem:label']", "Operating
System");
+ assertText("//[EMAIL PROTECTED]'department:label']", "Department");
+ assertText("//[EMAIL PROTECTED]'urgent:label']", "Urgent Processing
Requested");
assertFieldValue("email", "");
assertFieldValue("message", "");
@@ -941,7 +941,7 @@
}
@Test
- public void injected_script_links()
+ public void client_side_validation()
{
_selenium.open(BASE_URL);
@@ -953,13 +953,31 @@
"/assets/scriptaculous/prototype.js",
"/assets/scriptaculous/scriptaculous.js");
- // Selenium checks against the actual DOM which is great, but here it
reflects the other scriptaculous
- // libraries added before tapestry.js and its just not worth checking
here; soon we'll check behavior
- // rather than form.
-
-
- // More to come once the client-side validation settles down some
(easier to deal with once we get away from
- // window.alert().
+ clickAndWait("link=Clear Data");
+
+ // Notice: click, not click and wait.
+ _selenium.click("submit");
+
+ assertTextSeries(
+ "//li[%d]",
+ 1,
+ "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.");
+
+ _selenium.type("firstName", "Howard");
+ _selenium.type("lastName", "Lewis Ship");
+ _selenium.type("birthYear", "1000");
+ _selenium.click("submit");
+
+ assertText("//li", "Year of Birth requires a value of at least 1900.");
+
+ _selenium.type("birthYear", "1966");
+ _selenium.click("citizen");
+
+ clickAndWait("submit");
+
+ assertTextPresent("First Name: [Howard]");
}
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DefaultValidationDecoratorTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DefaultValidationDecoratorTest.java?view=diff&rev=513061&r1=513060&r2=513061
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DefaultValidationDecoratorTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DefaultValidationDecoratorTest.java
Wed Feb 28 15:29:38 2007
@@ -34,7 +34,7 @@
replay();
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideLabel(null, null);
@@ -56,7 +56,7 @@
Element e = writer.element("label", "accesskey", "f");
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideLabel(field, e);
@@ -80,7 +80,7 @@
Element e = writer.element("label", "accesskey", "f", "class", "foo");
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideLabel(field, e);
@@ -116,7 +116,7 @@
"size",
"30");
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideField(field);
@@ -139,7 +139,7 @@
replay();
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideField(field);
@@ -158,7 +158,7 @@
replay();
- ValidationDecorator decorator = new DefaultValidationDecorator(env);
+ ValidationDecorator decorator = new DefaultValidationDecorator(env,
null, null);
decorator.insideLabel(field, null);