Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java Tue Feb 27 14:11:23 2007 @@ -14,7 +14,11 @@ package org.apache.tapestry.validator; +import static org.apache.tapestry.TapestryUtils.quote; + import org.apache.tapestry.Field; +import org.apache.tapestry.MarkupWriter; +import org.apache.tapestry.PageRenderSupport; import org.apache.tapestry.ValidationException; import org.apache.tapestry.Validator; import org.apache.tapestry.ioc.MessageFormatter; @@ -33,7 +37,12 @@ String value) throws ValidationException { if (value.length() < constraintValue) - throw new ValidationException(formatter.format(constraintValue, field.getLabel())); + throw new ValidationException(buildMessage(formatter, field, constraintValue)); + } + + private String buildMessage(MessageFormatter formatter, Field field, Integer constraintValue) + { + return formatter.format(constraintValue, field.getLabel()); } public Class<Integer> getConstraintType() @@ -49,5 +58,15 @@ public Class<String> getValueType() { return String.class; + } + + public void render(Field field, Integer constraintValue, MessageFormatter formatter, + MarkupWriter writer, PageRenderSupport pageRenderSupport) + { + pageRenderSupport.addScript( + "Tapestry.Field.minlength('%s', %d, %s);", + field.getClientId(), + constraintValue, + quote(buildMessage(formatter, field, constraintValue))); } }
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java Tue Feb 27 14:11:23 2007 @@ -14,7 +14,11 @@ package org.apache.tapestry.validator; +import static org.apache.tapestry.TapestryUtils.quote; + import org.apache.tapestry.Field; +import org.apache.tapestry.MarkupWriter; +import org.apache.tapestry.PageRenderSupport; import org.apache.tapestry.ValidationException; import org.apache.tapestry.Validator; import org.apache.tapestry.ioc.MessageFormatter; @@ -34,7 +38,12 @@ throws ValidationException { if (value == null || value.toString().equals("")) - throw new ValidationException(formatter.format(field.getLabel())); + throw new ValidationException(buildMessage(formatter, field)); + } + + private String buildMessage(MessageFormatter formatter, Field field) + { + return formatter.format(field.getLabel()); } public Class<Void> getConstraintType() @@ -50,5 +59,15 @@ public Class<Object> getValueType() { return Object.class; + } + + public void render(Field field, Void constraintValue, MessageFormatter formatter, + MarkupWriter writer, PageRenderSupport pageRenderSupport) + { + pageRenderSupport.addScript( + "Tapestry.Field.required('%s', %s);", + field.getClientId(), + quote(buildMessage(formatter, field))); + } } 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=512442&r1=512441&r2=512442 ============================================================================== --- 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 Tue Feb 27 14:11:23 2007 @@ -13,12 +13,14 @@ # limitations under the License. # We try to keep these consistent, with the constraint value (if applicable) -# as the first parameter, and the field's label as the second parameter. +# as the first parameter, and the field's label as the second parameter. Occasionally +# we must use specific indexing when that's not the best order. required=You must provide a value for %s. minimum-string-length=You must provide at least %d characters for %s. maximum-string-length=You may provide at most %d characters for %s. min-integer=%2$s requires a value of at least %1$d. +max-integer=%2$s requires a value no larger than %1$d. # This is where the translator messages go. Added: 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=auto&rev=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js (added) +++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/tapestry.js Tue Feb 27 14:11:23 2007 @@ -0,0 +1,182 @@ +// 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. + +var Tapestry = { + + registerForm : function(form) { + form = $(form); + + form.onsubmit = function() { + var event = new Tapestry.FormEvent(form); + + form.getElements().each(function (element) { + if (element.fieldEventManager != undefined) { + event.field = element; + element.fieldEventManager.validateInput(event); + + if (event.abort) throw $break; + } + }); + + return event.result; + }; + + form.invalidField = function(field, event, message) { + + field = $(field); + if (field.focus) field.focus(); + if (field.select) field.select(); + + window.alert(message); + + // While we're still using the primitive popup system, we need to abort the event + // after displaying the alert. + event.abort = true; + }; + + }, + + FormEvent : Class.create(), + + FieldEventManager : Class.create(), + + // Adds a validator for a field. A FieldEventManager is added, if necessary. + // The validator will be called only for non-blank values, unless acceptBlank is + // true (in most cases, acceptBlank is flase). The validator is a function + // that accepts the current field value as its first parameter, and a + // Tapestry.FormEvent as its second. It can invoke recordError() on the event + // if the input is not valid. + + addValidator : function(field, acceptBlank, validator) { + field = $(field); + + if (field.fieldEventManager == undefined) new Tapestry.FieldEventManager(field); + + field.fieldEventManager.addValidator(acceptBlank, validator); + } + +}; + +// Collection of field based functions related to validation. + +Tapestry.Field = { + required : function(field, message) { + Tapestry.addValidator(field, true, function(value, event) { + if (value == '') + event.recordError(message); + }); + }, + + minlength : function(field, length, message) { + Tapestry.addValidator(field, false, function(value, event) { + if (value.length < length) + event.recordError(message); + }); + }, + + maxlength : function(field, maxlength, message) { + Tapestry.addValidator(field, false, function(value, event) { + if (value.length > maxlength) + event.recordError(message); + }); + }, + + min : function(field, minValue, message) { + Tapestry.addValidator(field, false, function(value, event) { + if (value < minValue) + event.recordError(message); + }); + }, + + max : function(field, maxValue, message) { + Tapestry.addValidator(field, false, function(value, event) { + if (value > maxValue) + event.recordError(message); + }); + } +}; + + +// A Tapestry.FormEvent is used when the form sends presubmit and submit events to +// a FieldEventManager. It allows the associated handlers to indirectly invoke +// the Form's invalidField() method, and it tracks a result flag (true for success == +// no field errors, false if any field errors). + +Tapestry.FormEvent.prototype = { + + initialize : function(form) { + this.form = $(form); + this.result = true; + }, + + // Invoked by a validator function (which is passed the event) to record an error + // for the associated field. The event knows the field and form and invoke's + // the (added) form method invalidField(). Sets the event's result field to false + // (i.e., don't allow the form to submit), and sets the event's error field to + // true. + + recordError : function(message) { + this.form.invalidField(this.field, this, message); + this.result = false; + this.error = true; + } +}; + +Tapestry.FieldEventManager.prototype = { + + initialize : function(field) { + + $(field).fieldEventManager = this; + + this.validators = [ ]; + }, + + // Adds a validator. acceptBlank is true if the validator should be invoked regardless of + // the value. Usually acceptBlank is false, meaning that the validator will be skipped if + // the field's value is blank. The validator itself is a function that is passed the + // field's value and the Tapestry.FormEvent object. When a validator invokes event.recordError(), + // any subsequent validators for that field are skipped. + + addValidator : function(acceptBlank, validator) { + + this.validators.push([ acceptBlank, validator]); + }, + + // Invoked from the Form's onsubmit event handler. Gets the fields value and invokes + // each validator (unless the value is blank) until a validator returns false. Validators + // should not modify the field's value. + + validateInput : function(event) { + var value = $F(event.field); + var isBlank = (value == ''); + + event.error = false; + + this.validators.each(function(tuple) { + + var acceptBlank = tuple[0]; + var validator = tuple[1]; + + if (acceptBlank || !isBlank) { + + validator(value, event); + + // event.error is set by Tapestry.FormEvent.recordError(). + + if (event.error) throw $break; + } + }); + } +}; + \ No newline at end of file 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=512442&r1=512441&r2=512442 ============================================================================== --- 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 27 14:11:23 2007 @@ -1,8 +1,8 @@ <t:comp type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> - <h1>BeanEditor Component Demo</h1> + <h1>${pageTitle}</h1> - <t:comp id="edit" object="registrationData" submitlabel="Register"> + <t:comp id="edit" submitlabel="Register"> <t:parameter name="firstName"> <label t:type="Label" for="firstName" /> <input t:type="TextField" Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html Tue Feb 27 14:11:23 2007 @@ -117,7 +117,7 @@ <a t:type="PageLink" page="pagelinkcontext">PageLink Context Demo</a> -- passing explicit context in a page render link </li> <li> - <a t:type="pagelink" page="scriptdemo">Script Demo</a> -- basic JavaScript integration + <a t:type="pagelink" page="ValidBeanEditorDemo">Client Validation Demo</a> --BeanEditor with validation enabled </li> </ul> </td> Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/TapestryUtilsTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/TapestryUtilsTest.java?view=auto&rev=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/TapestryUtilsTest.java (added) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/TapestryUtilsTest.java Tue Feb 27 14:11:23 2007 @@ -0,0 +1,30 @@ +// Copyright 2007 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TapestryUtilsTest extends Assert +{ + @Test + public void string_quoting() + { + assertEquals( + TapestryUtils.quote("Suzy said: \"It's not the proper time\"."), + "'Suzy said: \\\"It\\'s not the proper time\\\".'"); + + } +} Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/corelib/components/SelectTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/corelib/components/SelectTest.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/corelib/components/SelectTest.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/corelib/components/SelectTest.java Tue Feb 27 14:11:23 2007 @@ -31,7 +31,7 @@ import org.apache.tapestry.internal.OptionGroupModelImpl; import org.apache.tapestry.internal.OptionModelImpl; import org.apache.tapestry.internal.SelectModelImpl; -import org.apache.tapestry.internal.TapestryUtils; +import org.apache.tapestry.internal.TapestryInternalUtils; import org.apache.tapestry.internal.services.MarkupWriterImpl; import org.apache.tapestry.internal.test.InternalBaseTestCase; import org.apache.tapestry.ioc.internal.util.CollectionFactory; @@ -79,7 +79,7 @@ @Test public void just_options() throws Exception { - List<OptionModel> options = TapestryUtils + List<OptionModel> options = TapestryInternalUtils .toOptionModels("fred=Fred Flintstone,barney=Barney Rubble"); Select select = new Select(); @@ -150,9 +150,9 @@ @Test public void option_groups() throws Exception { - OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryUtils + OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils .toOptionModels("Fred,Barney")); - OptionGroupModel wives = new OptionGroupModelImpl("Wives", true, TapestryUtils + OptionGroupModel wives = new OptionGroupModelImpl("Wives", true, TapestryInternalUtils .toOptionModels("Wilma,Betty")); List<OptionGroupModel> groupModels = CollectionFactory.newList(husbands, wives); @@ -175,12 +175,12 @@ @Test public void option_groups_precede_ungroup_options() throws Exception { - OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryUtils + OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils .toOptionModels("Fred,Barney")); Select select = new Select(); - select.setModel(new SelectModelImpl(Collections.singletonList(husbands), TapestryUtils + select.setModel(new SelectModelImpl(Collections.singletonList(husbands), TapestryInternalUtils .toOptionModels("Wilma,Betty"))); select.setValue("Fred"); @@ -200,7 +200,7 @@ { Map<String, String> attributes = Collections.singletonMap("class", "pixie"); - OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryUtils + OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils .toOptionModels("Fred,Barney"), attributes); Select select = new Select(); 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=512442&r1=512441&r2=512442 ============================================================================== --- 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 27 14:11:23 2007 @@ -945,7 +945,7 @@ { _selenium.open(BASE_URL); - clickAndWait("link=Script Demo"); + clickAndWait("link=Client Validation Demo"); assertTextSeries( "//script[%d]/@src", @@ -953,5 +953,13 @@ "/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(). + } } Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java Tue Feb 27 14:11:23 2007 @@ -21,7 +21,8 @@ public class BeanEditorDemo { - @Component + @Component(parameters = + { "clientValidation=clientValidation", "object=registrationData" }) private BeanEditForm _edit; @ApplicationState @@ -41,5 +42,15 @@ { _data = null; _edit.getForm().clearErrors(); + } + + public boolean getClientValidation() + { + return false; + } + + public String getPageTitle() + { + return "BeanEditor Component Demo"; } } Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ValidBeanEditorDemo.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ValidBeanEditorDemo.java?view=auto&rev=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ValidBeanEditorDemo.java (added) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ValidBeanEditorDemo.java Tue Feb 27 14:11:23 2007 @@ -0,0 +1,32 @@ +// Copyright 2007 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry.integration.app1.pages; + +public class ValidBeanEditorDemo extends BeanEditorDemo +{ + + @Override + public boolean getClientValidation() + { + return true; + } + + @Override + public String getPageTitle() + { + return "Client Validation / BeanEditor Demo"; + } + +} Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DataBean.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DataBean.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DataBean.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/DataBean.java Tue Feb 27 14:11:23 2007 @@ -18,7 +18,7 @@ /** * Used as test when setting the order of properties via - * [EMAIL PROTECTED] TapestryUtils#orderProperties(org.apache.tapestry.ioc.services.ClassPropertyAdapter, ClassFactory, java.util.List)}. + * [EMAIL PROTECTED] TapestryInternalUtils#orderProperties(org.apache.tapestry.ioc.services.ClassPropertyAdapter, ClassFactory, java.util.List)}. */ public class DataBean { Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryInternalUtilsTest.java (from r510990, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryUtilsTest.java) URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryInternalUtilsTest.java?view=diff&rev=512442&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryUtilsTest.java&r1=510990&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryInternalUtilsTest.java&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryUtilsTest.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/TapestryInternalUtilsTest.java Tue Feb 27 14:11:23 2007 @@ -37,7 +37,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -public class TapestryUtilsTest extends InternalBaseTestCase +public class TapestryInternalUtilsTest extends InternalBaseTestCase { private ClassFactory _classFactory; @@ -60,7 +60,7 @@ @Test public void close_null_is_noop() { - TapestryUtils.close(null); + TapestryInternalUtils.close(null); } @Test @@ -72,7 +72,7 @@ replay(); - TapestryUtils.close(c); + TapestryInternalUtils.close(c); verify(); } @@ -87,7 +87,7 @@ replay(); - TapestryUtils.close(c); + TapestryInternalUtils.close(c); verify(); } @@ -95,7 +95,7 @@ @Test(dataProvider = "decapitalize_inputs") public void decapitalize(String input, String expected) { - assertEquals(TapestryUtils.decapitalize(input), expected); + assertEquals(TapestryInternalUtils.decapitalize(input), expected); } @DataProvider(name = "decapitalize_inputs") @@ -113,7 +113,7 @@ @Test(dataProvider = "to_user_presentable") public void to_user_presentable(String input, String expected) { - assertEquals(TapestryUtils.toUserPresentable(input), expected); + assertEquals(TapestryInternalUtils.toUserPresentable(input), expected); } @DataProvider(name = "to_user_presentable") @@ -130,7 +130,7 @@ @Test public void map_from_keys_and_values() { - Map<String, String> map = TapestryUtils.mapFromKeysAndValues( + Map<String, String> map = TapestryInternalUtils.mapFromKeysAndValues( "fred", "flintstone", "barney", @@ -144,7 +144,7 @@ @Test public void string_to_option_model_just_label() { - OptionModel model = TapestryUtils.toOptionModel("Just A Label"); + OptionModel model = TapestryInternalUtils.toOptionModel("Just A Label"); assertEquals(model.getLabel(), "Just A Label"); assertEquals(model.getValue(), "Just A Label"); @@ -153,7 +153,7 @@ @Test public void string_to_option_model() { - OptionModel model = TapestryUtils.toOptionModel("my-value=Some Label"); + OptionModel model = TapestryInternalUtils.toOptionModel("my-value=Some Label"); assertEquals(model.getLabel(), "Some Label"); assertEquals(model.getValue(), "my-value"); @@ -162,7 +162,7 @@ @Test public void string_to_option_models() { - List<OptionModel> options = TapestryUtils.toOptionModels("UK,USA,DE=Germany"); + List<OptionModel> options = TapestryInternalUtils.toOptionModels("UK,USA,DE=Germany"); assertEquals(options.size(), 3); @@ -181,7 +181,7 @@ { Map<String, String> map = Collections.singletonMap("key", "value"); Map.Entry entry = map.entrySet().iterator().next(); - OptionModel model = TapestryUtils.toOptionModel(entry); + OptionModel model = TapestryInternalUtils.toOptionModel(entry); assertEquals(model.getLabel(), "value"); assertEquals(model.getValue(), "key"); @@ -195,7 +195,7 @@ map.put(2, null); map.put(3, "C"); - List<OptionModel> options = TapestryUtils.toOptionModels(map); + List<OptionModel> options = TapestryInternalUtils.toOptionModels(map); assertEquals(options.size(), 3); @@ -212,7 +212,7 @@ @Test public void whitespace_around_terms_is_trimmed() { - List<OptionModel> options = TapestryUtils.toOptionModels(" UK , USA , DE=Germany "); + List<OptionModel> options = TapestryInternalUtils.toOptionModels(" UK , USA , DE=Germany "); assertEquals(options.size(), 3); @@ -242,7 +242,7 @@ @Test public void parse_key_value() { - KeyValue kv = TapestryUtils.parseKeyValue("foo=bar"); + KeyValue kv = TapestryInternalUtils.parseKeyValue("foo=bar"); assertEquals(kv.getKey(), "foo"); assertEquals(kv.getValue(), "bar"); @@ -255,7 +255,7 @@ try { - TapestryUtils.parseKeyValue(input); + TapestryInternalUtils.parseKeyValue(input); unreachable(); } catch (IllegalArgumentException ex) @@ -267,7 +267,7 @@ @Test public void whitespace_trimmed_for_key_value() { - KeyValue kv = TapestryUtils.parseKeyValue(" mykey = myvalue "); + KeyValue kv = TapestryInternalUtils.parseKeyValue(" mykey = myvalue "); assertEquals(kv.getKey(), "mykey"); assertEquals(kv.getValue(), "myvalue"); @@ -282,7 +282,7 @@ replay(); - assertEquals(TapestryUtils.defaultOrder(conduit), 0); + assertEquals(TapestryInternalUtils.defaultOrder(conduit), 0); verify(); } @@ -299,7 +299,7 @@ replay(); - assertEquals(TapestryUtils.defaultOrder(conduit), 99); + assertEquals(TapestryInternalUtils.defaultOrder(conduit), 99); verify(); } @@ -307,12 +307,14 @@ @Test public void extract_id_from_property_expression() { - assertEquals(TapestryUtils.extractIdFromPropertyExpression("simpleName"), "simpleName"); assertEquals( - TapestryUtils.extractIdFromPropertyExpression("complex.name().withStuff"), + TapestryInternalUtils.extractIdFromPropertyExpression("simpleName"), + "simpleName"); + assertEquals( + TapestryInternalUtils.extractIdFromPropertyExpression("complex.name().withStuff"), "complexnamewithStuff"); assertEquals( - TapestryUtils.extractIdFromPropertyExpression("number99.withABullet"), + TapestryInternalUtils.extractIdFromPropertyExpression("number99.withABullet"), "number99withABullet"); } @@ -325,7 +327,9 @@ replay(); - assertEquals(TapestryUtils.defaultLabel("myid", messages, "myid-name-not-used"), "My Id"); + assertEquals( + TapestryInternalUtils.defaultLabel("myid", messages, "myid-name-not-used"), + "My Id"); verify(); } @@ -339,9 +343,10 @@ replay(); - assertEquals( - TapestryUtils.defaultLabel("foobarbazbiff", messages, "foo.bar().baz.biff()"), - "Biff"); + assertEquals(TapestryInternalUtils.defaultLabel( + "foobarbazbiff", + messages, + "foo.bar().baz.biff()"), "Biff"); verify(); } @@ -355,7 +360,7 @@ names.remove("class"); - List<String> sorted = TapestryUtils.orderProperties(adapter, _classFactory, names); + List<String> sorted = TapestryInternalUtils.orderProperties(adapter, _classFactory, names); assertEquals(sorted, Arrays.asList("firstName", "lastName", "age")); } @@ -369,7 +374,7 @@ names.remove("class"); - List<String> sorted = TapestryUtils.orderProperties(adapter, _classFactory, names); + List<String> sorted = TapestryInternalUtils.orderProperties(adapter, _classFactory, names); // Subclass properties listed after superclass properties, as desired. @@ -392,7 +397,7 @@ names.remove("class"); - List<String> sorted = TapestryUtils.orderProperties(adapter, _classFactory, names); + List<String> sorted = TapestryInternalUtils.orderProperties(adapter, _classFactory, names); // Property third has an explicit @Order Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImplTest.java?view=auto&rev=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImplTest.java (added) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImplTest.java Tue Feb 27 14:11:23 2007 @@ -0,0 +1,48 @@ +// 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 org.apache.tapestry.PageRenderSupport; +import org.apache.tapestry.internal.test.InternalBaseTestCase; +import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl; +import org.apache.tapestry.ioc.services.ClassFactory; +import org.apache.tapestry.services.Environment; +import org.apache.tapestry.services.EnvironmentalShadowBuilder; +import org.testng.annotations.Test; + +public class EnvironmentalShadowBuilderImplTest extends InternalBaseTestCase +{ + @Test + public void proxy_class() + { + PageRenderSupport delegate = newMock(PageRenderSupport.class); + ClassFactory factory = new ClassFactoryImpl(); + Environment env = newEnvironment(); + + train_peekRequired(env, PageRenderSupport.class, delegate); + + expect(delegate.allocateClientId("fred")).andReturn("barney"); + + replay(); + + EnvironmentalShadowBuilder builder = new EnvironmentalShadowBuilderImpl(factory, env); + + PageRenderSupport proxy = builder.build(PageRenderSupport.class); + + assertEquals(proxy.allocateClientId("fred"), "barney"); + + verify(); + } +} Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java Tue Feb 27 14:11:23 2007 @@ -38,7 +38,7 @@ replay(); - FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator); + FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null); fv.validate(null); @@ -57,7 +57,7 @@ replay(); - FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator); + FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null); fv.validate(""); @@ -78,7 +78,7 @@ replay(); - FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator); + FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null); fv.validate(value); @@ -99,7 +99,7 @@ replay(); - FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator); + FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator, null); fv.validate(null); Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java Tue Feb 27 14:11:23 2007 @@ -1,4 +1,4 @@ -// Copyright 2006 The Apache Software Foundation +// Copyright 2006, 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. @@ -63,7 +63,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); try { @@ -117,7 +117,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); FieldValidator fieldValidator = source.createValidator(field, "required", null); @@ -157,7 +157,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); FieldValidator fieldValidator = source.createValidator(field, "required", null); @@ -202,7 +202,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); FieldValidator fieldValidator = source.createValidators(field, "required"); @@ -265,7 +265,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); FieldValidator fieldValidator = source.createValidators(field, "required,minLength=15"); @@ -313,7 +313,7 @@ replay(); - FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, map); + FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, null, map); FieldValidator fieldValidator = source.createValidator(field, "minLength", "5"); Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java?view=auto&rev=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java (added) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java Tue Feb 27 14:11:23 2007 @@ -0,0 +1,94 @@ +// 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 org.apache.tapestry.Asset; +import org.apache.tapestry.PageRenderSupport; +import org.apache.tapestry.internal.test.InternalBaseTestCase; +import org.apache.tapestry.ioc.Resource; +import org.apache.tapestry.ioc.services.SymbolSource; +import org.apache.tapestry.services.AssetFactory; +import org.testng.annotations.Test; + +public class PageRenderSupportImplTest extends InternalBaseTestCase +{ + private static final String ASSET_URL = "/assets/foo/bar.pdf"; + + @Test + public void add_script_link_by_asset() + { + DocumentScriptBuilder builder = newDocumentScriptBuilder(); + Asset asset = newAsset(); + + train_toClientURL(asset, ASSET_URL); + builder.addScriptLink(ASSET_URL); + + replay(); + + PageRenderSupport support = new PageRenderSupportImpl(builder, null, null); + + support.addScriptLink(asset); + + verify(); + } + + @Test + public void add_script() + { + DocumentScriptBuilder builder = newDocumentScriptBuilder(); + + builder.addScript("Tapestry.Foo(\"bar\");"); + + replay(); + + PageRenderSupport support = new PageRenderSupportImpl(builder, null, null); + + support.addScript("Tapestry.Foo(\"%s\");", "bar"); + + verify(); + } + + @Test + public void add_classpath_script_link() + { + String path = "${root}/foo/bar.pdf"; + String expanded = "org/apache/tapestry/foo/bar.pdf"; + + DocumentScriptBuilder builder = newDocumentScriptBuilder(); + Asset asset = newAsset(); + Resource root = newResource(); + Resource file = newResource(); + SymbolSource source = newSymbolSource(); + AssetFactory factory = newAssetFactory(); + + train_expandSymbols(source, path, expanded); + + train_getRootResource(factory, root); + train_forFile(root, expanded, file); + + train_createAsset(factory, file, asset); + + train_toClientURL(asset, ASSET_URL); + builder.addScriptLink(ASSET_URL); + + replay(); + + PageRenderSupport support = new PageRenderSupportImpl(builder, source, factory); + + support.addClasspathScriptLink(path); + + verify(); + } +} Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java Tue Feb 27 14:11:23 2007 @@ -97,13 +97,4 @@ verify(); } - protected final void train_forLocale(Resource base, Locale locale, Resource resource) - { - expect(base.forLocale(locale)).andReturn(resource); - } - - protected final void train_forFile(Resource root, String path, Resource resource) - { - expect(root.forFile(path)).andReturn(resource); - } } Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html?view=diff&rev=512442&r1=512441&r2=512442 ============================================================================== --- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html (original) +++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html Tue Feb 27 14:11:23 2007 @@ -3,7 +3,7 @@ <p> Tapestry 5 form support with server-side validation. </p> - <t:comp type="Form"> + <t:comp type="Form" clientValidation="false"> <t:comp type="Errors"/>
