You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/07/09 00:04:30 UTC
svn commit: r420205 - in /tapestry/tapestry4/trunk/tapestry-framework/src:
java/org/apache/tapestry/engine/ java/org/apache/tapestry/form/
java/org/apache/tapestry/form/translator/
java/org/apache/tapestry/form/validator/ java/org/apache/tapestry/json/...
Author: jkuhnert
Date: Sat Jul 8 15:04:28 2006
New Revision: 420205
URL: http://svn.apache.org/viewvc?rev=420205&view=rev
Log:
Refactored validation profiles so that multiple error messages can be shown for one field as well as multiple
validators be run for one field.
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/TestJsonProperties.java
Removed:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TranslatorTestCase.java
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/EngineServiceLink.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractFormComponentContributor.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/AbstractTranslator.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/NumberTranslator.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Max.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxDate.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxLength.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Min.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinDate.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinLength.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Required.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONLiteral.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONObject.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings.properties
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings_en.properties
tapestry/tapestry4/trunk/tapestry-framework/src/js/build.xml
tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/validate/check.js
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form_validation.js
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/engine/EngineServiceLinkTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestDateTranslator.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestStringTranslator.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestRequired.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/DefaultPrimaryKeyConverterTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/ScriptUtilsTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/StrftimeTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestQueryParameterMap.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestIntValidator.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestNumberValidator.java
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/EngineServiceLink.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/EngineServiceLink.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/EngineServiceLink.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/EngineServiceLink.java Sat Jul 8 15:04:28 2006
@@ -156,8 +156,11 @@
String result = buffer.toString();
- result = _cycle.encodeURL(result);
-
+ //TODO: Portlets need this result encoded again via IRequestCycle.encodeURL(), need
+ // to find a way to do this that doesn't conflict with existing URL construction semantics. (the
+ // isStateful parameter would effectively be ignored in this class if we encoded the url again
+ // because that method adds sessionID information from the servlet container ) JIRA issue TAPESTRY-802
+
return result;
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractFormComponentContributor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractFormComponentContributor.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractFormComponentContributor.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractFormComponentContributor.java Sat Jul 8 15:04:28 2006
@@ -17,7 +17,6 @@
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.json.JSONArray;
import org.apache.tapestry.json.JSONObject;
/**
@@ -81,9 +80,6 @@
*/
public void accumulateProperty(JSONObject profile, String key, Object value)
{
- if (!profile.has(key))
- profile.put(key, new JSONArray());
-
profile.accumulate(key, value);
}
@@ -100,13 +96,14 @@
* @param property
* The property to store.
*/
- public void setProfileProperty(IFormComponent field, JSONObject profile,
+ public void accumulateProfileProperty(IFormComponent field, JSONObject profile,
String key, Object property)
{
if (!profile.has(field.getClientId()))
profile.put(field.getClientId(), new JSONObject());
JSONObject fieldProps = profile.getJSONObject(field.getClientId());
- fieldProps.put(key, property);
+
+ accumulateProperty(fieldProps, key, property);
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/AbstractTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/AbstractTranslator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/AbstractTranslator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/AbstractTranslator.java Sat Jul 8 15:04:28 2006
@@ -96,9 +96,9 @@
protected String buildMessage(ValidationMessages messages, IFormComponent field, String key)
{
String label = field.getDisplayName();
-
+
Object[] parameters = getMessageParameters(messages.getLocale(), label);
-
+
return messages.formatValidationMessage(_message, key, parameters);
}
@@ -116,7 +116,7 @@
{
super.renderContribution(writer, cycle, context, field);
- if (!_trim) {
+ if (_trim) {
JSONObject profile = context.getProfile();
accumulateProperty(profile, ValidationConstants.TRIM, field.getClientId());
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/NumberTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/NumberTranslator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/NumberTranslator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/translator/NumberTranslator.java Sat Jul 8 15:04:28 2006
@@ -22,7 +22,6 @@
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.TapestryUtils;
import org.apache.tapestry.form.FormComponentContributorContext;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.json.JSONLiteral;
@@ -115,27 +114,27 @@
{
super.renderContribution(writer, cycle, context, field);
- String message = TapestryUtils.enquote(buildMessage(context, field, getMessageKey()));
+ String message = buildMessage(context, field, getMessageKey());
JSONObject profile = context.getProfile();
-
if (!profile.has(ValidationConstants.CONSTRAINTS)) {
profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
}
+
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
DecimalFormat format = getDecimalFormat(context.getLocale());
- cons.put(field.getClientId(),
+ cons.accumulate(field.getClientId(),
new JSONLiteral("[dojo.validate.isRealNumber,{"
- + "places:" + format.getMaximumIntegerDigits()) + ","
+ + ((format.getMaximumFractionDigits() > 0)
+ ? "" : "places:" + format.getMaximumFractionDigits() + ",")
+ "decimal:"
+ JSONObject.quote(format.getDecimalFormatSymbols().getDecimalSeparator()) + ","
+ "separator:" + JSONObject.quote(format.getDecimalFormatSymbols().getGroupingSeparator())
- + "}]");
+ + "}]"));
- setProfileProperty(field, profile,
- ValidationConstants.CONSTRAINTS, message);
+ accumulateProfileProperty(field, profile, ValidationConstants.CONSTRAINTS, message);
}
/**
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java Sat Jul 8 15:04:28 2006
@@ -21,7 +21,6 @@
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.TranslatedField;
import org.apache.tapestry.form.translator.Translator;
-import org.apache.tapestry.json.JSONArray;
import org.apache.tapestry.json.JSONObject;
/**
@@ -94,14 +93,15 @@
* @param property
* The property to store.
*/
- public void setProfileProperty(IFormComponent field, JSONObject profile,
+ public void accumulateProfileProperty(IFormComponent field, JSONObject profile,
String key, Object property)
{
if (!profile.has(field.getClientId()))
profile.put(field.getClientId(), new JSONObject());
JSONObject fieldProps = profile.getJSONObject(field.getClientId());
- fieldProps.put(key, property);
+
+ accumulateProperty(fieldProps, key, property);
}
/**
@@ -113,9 +113,6 @@
*/
public void accumulateProperty(JSONObject profile, String key, Object value)
{
- if (!profile.has(key))
- profile.put(key, new JSONArray());
-
profile.accumulate(key, value);
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java Sat Jul 8 15:04:28 2006
@@ -83,9 +83,10 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(), new JSONLiteral("[dojo.validate.isEmailAddress,false,true]"));
+ accumulateProperty(cons, field.getClientId(),
+ new JSONLiteral("[dojo.validate.isEmailAddress,false,true]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Max.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Max.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Max.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Max.java Sat Jul 8 15:04:28 2006
@@ -83,13 +83,13 @@
// TODO: Should find some way to provide this globally and cache.
DecimalFormatSymbols symbols = new DecimalFormatSymbols(context.getLocale());
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[dojo.validate.isInRange,{"
+ "max:" + _max + ","
+ "decimal:" + JSONObject.quote(symbols.getDecimalSeparator())
+ "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxDate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxDate.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxDate.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxDate.java Sat Jul 8 15:04:28 2006
@@ -92,7 +92,7 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[tapestry.form.datetime.isValidDate,{"
+ "max:"
+ JSONObject.quote(translator.format(field, context.getLocale(), _maxDate))
@@ -101,7 +101,7 @@
+ JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern()))
+ "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field, translator));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxLength.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxLength.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxLength.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MaxLength.java Sat Jul 8 15:04:28 2006
@@ -80,11 +80,11 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[dojo.validate.isText,{"
+ "maxlength:" + _maxLength + "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Min.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Min.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Min.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Min.java Sat Jul 8 15:04:28 2006
@@ -83,13 +83,13 @@
// TODO: Should find some way to provide this globally and cache.
DecimalFormatSymbols symbols = new DecimalFormatSymbols(context.getLocale());
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[dojo.validate.isInRange,{"
+ "min:" + _min + ","
+ "decimal:" + JSONObject.quote(symbols.getDecimalSeparator())
+ "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinDate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinDate.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinDate.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinDate.java Sat Jul 8 15:04:28 2006
@@ -98,7 +98,7 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[tapestry.form.datetime.isValidDate,{"
+ "min:"
+ JSONObject.quote(translator.format(field, context.getLocale(), _minDate))
@@ -107,7 +107,7 @@
+ JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern()))
+ "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field, translator));
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinLength.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinLength.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinLength.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/MinLength.java Sat Jul 8 15:04:28 2006
@@ -84,11 +84,11 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[dojo.validate.isText,{"
+ "minlength:" + _minLength + "}]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java Sat Jul 8 15:04:28 2006
@@ -83,11 +83,11 @@
}
JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
- cons.put(field.getClientId(),
+ accumulateProperty(cons, field.getClientId(),
new JSONLiteral("[tapestry.form.validation.isValidPattern,\""
+ pattern + "\"]"));
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.CONSTRAINTS, buildMessage(context, field));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Required.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Required.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Required.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Required.java Sat Jul 8 15:04:28 2006
@@ -62,7 +62,7 @@
throw new ValidatorException(message, ValidationConstraint.REQUIRED);
}
}
-
+
private String buildMessage(ValidationMessages messages, IFormComponent field)
{
return messages.formatValidationMessage(
@@ -81,7 +81,7 @@
accumulateProperty(profile, ValidationConstants.REQUIRED, field.getClientId());
- setProfileProperty(field, profile,
+ accumulateProfileProperty(field, profile,
ValidationConstants.REQUIRED, buildMessage(context, field));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONLiteral.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONLiteral.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONLiteral.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONLiteral.java Sat Jul 8 15:04:28 2006
@@ -22,7 +22,6 @@
*/
public class JSONLiteral
{
-
private String _value;
public JSONLiteral(String value)
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONObject.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONObject.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONObject.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/JSONObject.java Sat Jul 8 15:04:28 2006
@@ -884,6 +884,8 @@
.toString(indentFactor, indent)); }
if (value instanceof JSONArray) { return (((JSONArray) value).toString(
indentFactor, indent)); }
+ if (JSONLiteral.class.isAssignableFrom(value.getClass()))
+ return value.toString();
return quote(value.toString());
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings.properties?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings.properties (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings.properties Sat Jul 8 15:04:28 2006
@@ -16,9 +16,9 @@
field-too-short=You must enter at least {0} characters for {1}.
invalid-date-format=Invalid date format for {0}. Format is {1}.
-invalid-int-format={0} must be an integer value.
+invalid-int-format={0} must be an integer value. Format is {1}.
invalid-format={0} is not in a recognized format.
-invalid-numeric-format={0} must be a numeric value.
+invalid-numeric-format={0} must be a numeric value. Format is {1}.
date-too-early={0} must be on or after {1}.
date-too-late={0} must be on or before {1}.
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings_en.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings_en.properties?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings_en.properties (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/valid/ValidationStrings_en.properties Sat Jul 8 15:04:28 2006
@@ -16,9 +16,9 @@
field-too-short=You must enter at least {0} characters for {1}.
invalid-date-format=Invalid date format for {0}. Format is {1}.
-invalid-int-format={0} must be an integer value.
+invalid-int-format={0} must be an integer value. Format is {1}.
invalid-format={0} is not in a recognized format.
-invalid-numeric-format={0} must be a numeric value.
+invalid-numeric-format={0} must be a numeric value. Format is {1}.
date-too-early={0} must be on or after {1}.
date-too-late={0} must be on or before {1}.
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/build.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/build.xml?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/build.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/build.xml Sat Jul 8 15:04:28 2006
@@ -22,14 +22,6 @@
-->
<project name="Tapestry Javascript" default="package">
- <!-- ====================================================== -->
- <!-- Properties/environment checks -->
- <!-- ====================================================== -->
- <property name="module.name" value="framework-js" />
- <property name="module.javac.target" value="1.5" />
- <property name="module.javac.source" value="1.5" />
- <property name="module.install.dir" value="${root.dir}/target/js" />
-
<property name="root.dir" value="../../.." />
<property file="${root.dir}/config/build.properties" />
<property name="profile.file" value="tapestry.profile.js" />
@@ -39,8 +31,6 @@
<taskdef name="dojo-test" classname="org.dojotoolkit.ant.DojoTestTask"
classpath="lib/ant-dojotest.jar" />
- <import file="${hivebuild.dir}/module.xml" />
-
<target name="check-dependencies" description="Ensures that dojo.dir is set.">
<fail message="dojo.dir not set" unless="dojo.dir" />
@@ -68,10 +58,6 @@
<exclude name="dojo/tests/**" />
</fileset>
</copy>
- </target>
-
- <target name="install" >
-
</target>
<!-- ====================================================== -->
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/validate/check.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/validate/check.js?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/validate/check.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/validate/check.js Sat Jul 8 15:04:28 2006
@@ -163,28 +163,40 @@
}
// Find invalid input fields.
- if ( typeof profile.constraints == "object" ) {
+ if(dojo.lang.isObject(profile.constraints)){
// constraint properties are the names of fields to be validated
- for (name in profile.constraints) {
+ for(name in profile.constraints){
var elem = form[name];
- if ( elem.type != "text" && elem.type != "textarea" && elem.type != "password" ) { continue; }
- // skip if blank - its optional unless required, in which case it is already listed as missing.
- if ( /^\s*$/.test(elem.value) ) { continue; }
-
+ if( (elem.type != "text")&&
+ (elem.type != "textarea")&&
+ (elem.type != "password")){
+ continue;
+ }
+ // skip if blank - its optional unless required, in which case it
+ // is already listed as missing.
+ if( /^\s*$/.test(elem.value)){ continue; }
+
var isValid = true;
// case 1: constraint value is validation function
- if ( typeof profile.constraints[name] == "function" ) {
+ if(dojo.lang.isFunction(profile.constraints[name])){
isValid = profile.constraints[name](elem.value);
+ }else if(dojo.lang.isArray(profile.constraints[name])){
+ // handle nested arrays for multiple constraints
+ if (dojo.lang.isArray(profile.constraints[name][0])) {
+ for (var i=0; i<profile.constraints[name].length; i++) {
+ isValid = dojo.validate.evaluateConstraint(profile, profile.constraints[name][i],
+ name, elem);
+ if (!isValid) { break; }
+ }
+ } else {
+ // case 2: constraint value is array, first elem is function,
+ // tail is parameters
+ isValid = dojo.validate.evaluateConstraint(profile, profile.constraints[name],
+ name, elem);
+ }
}
- // case 2: constraint value is array, first elem is function, tail is parameters
- else if ( profile.constraints[name] instanceof Array ) {
- var isValidSomething = profile.constraints[name][0];
- var params = profile.constraints[name].slice(1);
- params.unshift(elem.value);
- isValid = isValidSomething.apply(null, params);
- }
-
- if ( !isValid ) {
+
+ if(!isValid){
invalid[invalid.length] = elem.name;
}
}
@@ -208,4 +220,41 @@
}
return results;
+}
+
+/**
+ * Evaluates dojo.validate.check() constraints that are specified as array
+ * arguments. The arrays are expected to be in the format of:
+ *
+ * <pre>
+ * constraints:{
+ * fieldName: [functionToCall, param1, param2, etc.],
+ * fieldName: [[functionToCallFirst, param1],[functionToCallSecond,param2]]
+ * }
+ * </pre>
+ *
+ * This function evaluates a single array function in the format of:
+ * <pre>
+ * [functionName, argument1, argument2, etc]
+ * </pre>
+ *
+ * The function will be parsed out and evaluated against the incoming parameters.
+ *
+ * @param profile - The dojo.validate.check() profile that this evaluation is against.
+ * @param constraint - The single [] array of function and arguments for the function.
+ * @param fieldName - The form dom name of the field being validated.
+ * @param elem - The form element field.
+ *
+ * @return Boolean, True if constraint passed, false otherwise.
+ */
+dojo.validate.evaluateConstraint=function(profile, constraint, fieldName, elem){
+ var isValidSomething = constraint[0];
+ var params = constraint.slice(1);
+ params.unshift(elem.value);
+
+ if(typeof isValidSomething != "undefined"){
+ return isValidSomething.apply(null, params);
+ }
+
+ return false;
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js Sat Jul 8 15:04:28 2006
@@ -46,15 +46,23 @@
if (!props) return true; // form exists but no profile? just submit I guess..
if (!props.validateForm) return true;
- this.clearValidationDecorations(form, props);
-
- for (var i=0; i < props.profiles.length; i++) {
- var results=dojo.validate.check(form, props.profiles[i]);
+ try {
+ this.clearValidationDecorations(form, props);
- if (!this.processResults(form, results, props.profiles[i])) {
- this.summarizeErrors(form, results, props.profiles[i]);
- return false;
+ for (var i=0; i < props.profiles.length; i++) {
+ var results=dojo.validate.check(form, props.profiles[i]);
+
+ if (!this.processResults(form, results, props.profiles[i])) {
+ this.summarizeErrors(form, results, props.profiles[i]);
+ return false;
+ }
}
+ } catch (e) {
+ // since so many dynamic function calls may happen in here it's best that we
+ // catch all of them and log them or else peoples forms might still get submitted
+ // and they'd never be able to figure out what was wrong
+ dojo.log.exception("Error validating", e, true);
+ return false;
}
return true;
@@ -136,6 +144,7 @@
if (typeof form.elements[i].type == "undefined"
|| form.elements[i].type == "submit"
|| form.elements[i].type == "hidden") { continue; }
+
dojo.html.removeClass(form.elements[i], this.missingClass);
dojo.html.removeClass(form.elements[i], this.invalidClass);
}
@@ -157,7 +166,11 @@
var fields=results.getMissing();
for (var i=0; i<fields.length; i++){
if (profile[fields[i]] && profile[fields[i]]["required"]){
- merrs.push(profile[fields[i]]["required"]);
+ if (dojo.lang.isArray(profile[fields[i]]["required"])) {
+ for (var z=0; z < profile[fields[i]]["required"].length; z++)
+ merrs.push(profile[fields[i]]["required"][z]);
+ } else
+ merrs.push(profile[fields[i]]["required"]);
}
}
}
@@ -165,7 +178,11 @@
var fields=results.getInvalid();
for (var i=0; i<fields.length; i++){
if (profile[fields[i]] && profile[fields[i]]["constraints"]){
- ierrs.push(profile[fields[i]]["constraints"]);
+ if (dojo.lang.isArray(profile[fields[i]]["constraints"])) {
+ for (var z=0; z < profile[fields[i]]["constraints"].length; z++)
+ ierrs.push(profile[fields[i]]["constraints"][z]);
+ } else
+ ierrs.push(profile[fields[i]]["constraints"]);
}
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form_validation.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form_validation.js?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form_validation.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form_validation.js Sat Jul 8 15:04:28 2006
@@ -4,6 +4,7 @@
dojo.require("tapestry.test");
dojo.require("tapestry.form");
dojo.require("dojo.lang.*");
+dojo.require("dojo.validate.common");
function test_register_invalidform(){
try {
@@ -26,4 +27,9 @@
jum.assertTrue("formregForm", dojo.lang.isObject(tapestry.form.forms["regform"]));
jum.assertTrue("formregProfiles", dojo.lang.isArray(tapestry.form.forms["regform"].profiles));
jum.assertEquals("formregProfileLength", 0, tapestry.form.forms["regform"].profiles.length);
+}
+
+function test_validate_realNumber(){
+ var value="a12";
+ jum.assertFalse(value, dojo.validate.isRealNumber(value, {places:0,decimal:".",separator:","}));
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/engine/EngineServiceLinkTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/engine/EngineServiceLinkTest.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/engine/EngineServiceLinkTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/engine/EngineServiceLinkTest.java Sat Jul 8 15:04:28 2006
@@ -55,17 +55,12 @@
WebRequest request = newRequest();
IRequestCycle rc = newCycle();
- trainEncodeURL(
- rc,
- "/context/servlet?service=myservice",
- "/context/servlet?service=myservice;encoded");
-
EngineServiceLink l = new EngineServiceLink(rc, "/context/servlet", ENCODING, _urlCodec,
request, buildParameters("myservice", null), true);
replay();
- assertEquals("/context/servlet?service=myservice;encoded", l.getURL());
+ assertEquals("/context/servlet?service=myservice", l.getURL());
verify();
@@ -82,10 +77,6 @@
EngineServiceLink l = new EngineServiceLink(rc, "/ctx/app", ENCODING, _urlCodec, request,
buildParameters("foo", new String[]
{ "godzilla", "frodo" }), false);
-
- trainEncodeURL(rc,
- "/ctx/app?service=foo&sp=godzilla&sp=frodo",
- "/ctx/app?service=foo&sp=godzilla&sp=frodo");
replay();
@@ -104,11 +95,9 @@
EngineServiceLink l = new EngineServiceLink(rc, "/context/servlet", ENCODING, _urlCodec,
request, buildParameters("myservice", null), true);
- trainEncodeURL(rc, "/context/servlet", "/context/servlet;encoded");
-
replay();
-
- assertEquals("/context/servlet;encoded", l.getURL(null, false));
+
+ assertEquals("/context/servlet", l.getURL(null, false));
verify();
}
@@ -122,8 +111,6 @@
EngineServiceLink l = new EngineServiceLink(rc, "/context/servlet", ENCODING, _urlCodec,
request, buildParameters("myservice", null), false);
-
- trainEncodeURL(rc, "/context/servlet#anchor", "/context/servlet#anchor");
replay();
@@ -139,10 +126,6 @@
EngineServiceLink l = new EngineServiceLink(rc, "/context/servlet", ENCODING, _urlCodec,
request, buildParameters("myservice", null), false);
-
- trainEncodeURL(rc,
- "/context/servlet?service=myservice#anchor",
- "/context/servlet?service=myservice#anchor");
replay();
@@ -165,10 +148,6 @@
trainGetServerName(request, "TESTSERVER.COM");
- trainEncodeURL(rc,
- "HTTP://TESTSERVER.COM:9187/ctx/app?service=myservice",
- "HTTP://TESTSERVER.COM:9187/ctx/app?service=myservice");
-
replay();
assertEquals("HTTP://TESTSERVER.COM:9187/ctx/app?service=myservice", l.getAbsoluteURL());
@@ -183,10 +162,6 @@
EngineServiceLink l = new EngineServiceLink(rc, "/ctx/app", ENCODING, _urlCodec, request,
buildParameters("myservice", null), false);
-
- trainEncodeURL(rc,
- "https://myserver.net:9100/ctx/app?service=myservice",
- "https://myserver.net:9100/ctx/app?service=myservice");
replay();
@@ -208,10 +183,6 @@
trainGetScheme(request, "http");
trainGetServerName(request, "myserver.net");
trainGetServerPort(request, 80);
-
- trainEncodeURL(rc,
- "/ctx/app?service=myservice#myanchor",
- "/ctx/app?service=myservice#myanchor");
replay();
@@ -234,10 +205,6 @@
IRequestCycle rc = newCycle();
trainGetScheme(request, "http");
-
- trainEncodeURL(rc,
- "https://override.net:8080/ctx/app?service=myservice#myanchor",
- "https://override.net:8080/ctx/app?service=myservice#myanchor");
replay();
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java Sat Jul 8 15:04:28 2006
@@ -85,9 +85,9 @@
checkOrder(field, false);
expect(field.getDisplayName()).andReturn(displayName);
-
- expect(field.getClientId()).andReturn(clientId).times(count);
-
+
+ expect(field.getClientId()).andReturn(clientId).anyTimes();
+
return field;
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestDateTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestDateTranslator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestDateTranslator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestDateTranslator.java Sat Jul 8 15:04:28 2006
@@ -14,6 +14,7 @@
package org.apache.tapestry.form.translator;
+import static org.easymock.EasyMock.expect;
import static org.testng.AssertJUnit.assertEquals;
import java.util.Calendar;
@@ -23,8 +24,10 @@
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.FormComponentContributorContext;
+import org.apache.tapestry.form.FormComponentContributorTestCase;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.ValidationMessages;
+import org.apache.tapestry.json.JSONObject;
import org.apache.tapestry.valid.ValidationConstraint;
import org.apache.tapestry.valid.ValidationStrings;
import org.apache.tapestry.valid.ValidatorException;
@@ -38,7 +41,7 @@
* @since 4.0
*/
@Test
-public class TestDateTranslator extends TranslatorTestCase
+public class TestDateTranslator extends FormComponentContributorTestCase
{
private Calendar _calendar = Calendar.getInstance();
@@ -234,12 +237,14 @@
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
-
- IFormComponent field = newFieldWithClientId("foo");
-
+
+ JSONObject json = new JSONObject();
+
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
- trainTrim(context, "foo");
+ expect(context.getProfile()).andReturn(json);
+
+ IFormComponent field = newFieldWithClientId("foo");
replay();
@@ -249,6 +254,8 @@
dt.renderContribution(writer, cycle, context, field);
verify();
-
+
+ assertEquals("{\"trim\":\"foo\"}",
+ json.toString());
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java Sat Jul 8 15:04:28 2006
@@ -14,6 +14,7 @@
package org.apache.tapestry.form.translator;
+import static org.easymock.EasyMock.expect;
import static org.testng.AssertJUnit.assertEquals;
import java.util.Locale;
@@ -24,6 +25,7 @@
import org.apache.tapestry.form.FormComponentContributorTestCase;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.ValidationMessages;
+import org.apache.tapestry.json.JSONObject;
import org.apache.tapestry.valid.ValidationConstraint;
import org.apache.tapestry.valid.ValidationStrings;
import org.apache.tapestry.valid.ValidatorException;
@@ -196,25 +198,30 @@
NumberTranslator translator = new NumberTranslator();
IFormComponent field = newField("Number Field", "numberField", 1);
+ JSONObject json = new JSONObject();
+
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
- context.includeClasspathScript(translator.defaultScript());
+ expect(context.getProfile()).andReturn(json);
trainGetLocale(context, Locale.ENGLISH);
- trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER, new Object[]
- { "Number Field", "#" }, "invalid number message");
-
- context.addSubmitHandler("function(event) { Tapestry.validate_number(event, 'numberField', 'invalid number message'); }");
+ trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER,
+ new Object[] { "Number Field", "#" }, "invalid number message");
replay();
-
+
translator.renderContribution(writer, cycle, context, field);
-
+
verify();
+
+ assertEquals("{\"numberField\":{\"constraints\":\"invalid number message\"},"
+ + "\"constraints\":{\"numberField\":[dojo.validate.isRealNumber,"
+ + "{places:0,decimal:\".\",separator:\",\"}]}}",
+ json.toString());
}
public void testMessageRenderContribution()
@@ -227,60 +234,69 @@
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
+ JSONObject json = new JSONObject();
+
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
- context.includeClasspathScript(translator.defaultScript());
-
+ expect(context.getProfile()).andReturn(json);
+
trainGetLocale(context, Locale.ENGLISH);
trainBuildMessage(
context,
messageOverride,
ValidationStrings.INVALID_NUMBER,
- new Object[]
- { "Number Field", "#" },
+ new Object[] { "Number Field", "#" },
"Blah Blah 'Field Name' Blah.");
-
- context.addSubmitHandler("function(event) { Tapestry.validate_number(event, 'myfield', 'Blah Blah \\'Field Name\\' Blah.'); }");
-
+
replay();
translator.setMessage(messageOverride);
translator.renderContribution(writer, cycle, context, field);
-
+
verify();
+
+ assertEquals("{\"myfield\":{\"constraints\":\"Blah Blah \'Field Name\' Blah.\"},"
+ + "\"constraints\":{\"myfield\":[dojo.validate.isRealNumber,"
+ + "{places:0,decimal:\".\",separator:\",\"}]}}",
+ json.toString());
}
-
+
public void testTrimRenderContribution()
{
IFormComponent field = newField("Number Field", "myfield", 2);
-
+
NumberTranslator translator = new NumberTranslator();
-
+ JSONObject json = new JSONObject();
+
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
-
- context.includeClasspathScript(translator.defaultScript());
- trainTrim(context, "myfield");
-
+ expect(context.getProfile()).andReturn(json);
+
trainGetLocale(context, Locale.ENGLISH);
-
+
trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER, new Object[]
{ "Number Field", "#" }, "invalid number message");
-
- context
- .addSubmitHandler("function(event) { Tapestry.validate_number(event, 'myfield', 'invalid number message'); }");
-
+
+ expect(context.getProfile()).andReturn(json);
+
replay();
translator.setTrim(true);
-
+
translator.renderContribution(writer, cycle, context, field);
-
+
verify();
+
+ assertEquals("{\"myfield\":{\"constraints\":\"invalid number message\"},"
+ + "\"constraints\":{\"myfield\":[dojo.validate.isRealNumber,"
+ + "{places:0,decimal:\".\",separator:\",\"}]},"
+ + "\"trim\":\"myfield\"}",
+ json.toString());
+
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestStringTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestStringTranslator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestStringTranslator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/translator/TestStringTranslator.java Sat Jul 8 15:04:28 2006
@@ -14,12 +14,15 @@
package org.apache.tapestry.form.translator;
+import static org.easymock.EasyMock.expect;
import static org.testng.AssertJUnit.assertEquals;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.FormComponentContributorContext;
+import org.apache.tapestry.form.FormComponentContributorTestCase;
import org.apache.tapestry.form.IFormComponent;
+import org.apache.tapestry.json.JSONObject;
import org.apache.tapestry.valid.ValidatorException;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;
@@ -31,7 +34,7 @@
* @since 4.0
*/
@Test
-public class TestStringTranslator extends TranslatorTestCase
+public class TestStringTranslator extends FormComponentContributorTestCase
{
private StringTranslator _translator = new StringTranslator();
@@ -163,12 +166,14 @@
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
+ JSONObject json = new JSONObject();
+
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
-
+
+ expect(context.getProfile()).andReturn(json);
+
IFormComponent field = newFieldWithClientId("myfield");
-
- trainTrim(context, "myfield");
-
+
replay();
Translator t = new StringTranslator("trim");
@@ -176,6 +181,9 @@
t.renderContribution(writer, cycle, context, field);
verify();
+
+ assertEquals("{\"trim\":\"myfield\"}",
+ json.toString());
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestRequired.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestRequired.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestRequired.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestRequired.java Sat Jul 8 15:04:28 2006
@@ -16,7 +16,6 @@
import static org.easymock.EasyMock.expect;
import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertSame;
import java.util.Collections;
@@ -26,7 +25,6 @@
import org.apache.tapestry.form.FormComponentContributorContext;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.ValidationMessages;
-import org.apache.tapestry.json.JSONArray;
import org.apache.tapestry.json.JSONObject;
import org.apache.tapestry.valid.ValidationConstants;
import org.apache.tapestry.valid.ValidationConstraint;
@@ -189,13 +187,8 @@
verify();
- assertNotNull(json.get(ValidationConstants.REQUIRED));
- JSONArray arr = json.getJSONArray(ValidationConstants.REQUIRED);
- assertEquals("fred", arr.getString(0));
-
- assertNotNull(json.get("fred"));
- JSONObject obj = json.getJSONObject("fred");
- assertEquals("Default\\Message for Fred.", obj.getString(ValidationConstants.REQUIRED));
+ assertEquals("{\"fred\":{\"required\":\"Default\\\\Message for Fred.\"},\"required\":\"fred\"}",
+ json.toString());
}
public void testIsRequired()
Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/TestJsonProperties.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/TestJsonProperties.java?rev=420205&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/TestJsonProperties.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/json/TestJsonProperties.java Sat Jul 8 15:04:28 2006
@@ -0,0 +1,74 @@
+package org.apache.tapestry.json;
+// Copyright Jul 8, 2006 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
+import org.apache.tapestry.BaseComponentTestCase;
+import org.testng.annotations.Test;
+
+/**
+ * Tests functionality of the core {@link JSONObject} .
+ *
+ * @author jkuhnert
+ */
+@Test
+public class TestJsonProperties extends BaseComponentTestCase
+{
+
+ public void testLiteralArrays()
+ {
+ JSONObject json = new JSONObject();
+
+ json.accumulate("key", new JSONLiteral("[value1]"));
+ json.accumulate("key", new JSONLiteral("[value2]"));
+ json.accumulate("key", new JSONLiteral("[value3]"));
+
+ assertEquals("{\"key\":[[value1],[value2],[value3]]}",
+ json.toString());
+
+ JSONObject container = new JSONObject();
+ container.put("container", json);
+
+ assertEquals("{\"container\":{\"key\":[[value1],[value2],[value3]]}}",
+ container.toString());
+ }
+
+ public void testLiteralArrayContainer()
+ {
+ JSONObject profile = new JSONObject();
+ profile.put("constraints", new JSONObject());
+
+ JSONObject cons = profile.getJSONObject("constraints");
+
+ if (!cons.has("key"))
+ cons.put("key", new JSONArray());
+
+ Locale locale = Locale.ENGLISH;
+ DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
+
+ cons.accumulate("key",
+ new JSONLiteral("[something,value1:{key:\"value\",key2:"
+ + JSONObject.quote(symbols.getGroupingSeparator()) + "}]"));
+ cons.accumulate("key", new JSONLiteral("[value2]"));
+ cons.accumulate("key", new JSONLiteral("[value3]"));
+
+ assertEquals("{\"constraints\":{\"key\":[[something,value1:{key:\"value\",key2:\",\"}],[value2],[value3]]}}",
+ profile.toString());
+ }
+
+}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java Sat Jul 8 15:04:28 2006
@@ -123,8 +123,6 @@
trainGetEngine(cycle, engine);
trainGetOutputEncoding(engine, "utf-8");
-
- trainEncodeURL(cycle, "/context/app?service=myservice", "/context/app?service=myservice");
replay();
@@ -167,9 +165,7 @@
trainGetEngine(cycle, engine);
trainGetOutputEncoding(engine, "utf-8");
-
- trainEncodeURL(cycle, "/context/app?foo=bar&service=myservice", "{encoded}");
-
+
replay();
LinkFactoryImpl lf = new LinkFactoryImpl();
@@ -181,14 +177,14 @@
lf.setRequest(request);
lf.setPersistenceStrategySource(new MockSource());
lf.setRequestCycle(cycle);
-
+
lf.initializeService();
-
+
Map parameters = new HashMap();
-
+
ILink link = lf.constructLink(service, false, parameters, true);
-
- assertEquals("{encoded}", link.getURL());
+
+ assertEquals("/context/app?foo=bar&service=myservice", link.getURL());
verify();
}
@@ -203,8 +199,7 @@
trainGetEngine(cycle, engine);
trainGetOutputEncoding(engine, "utf-8");
- trainEncodeURL(cycle, "/context/app?service=myservice", "/context/app?service=myservice");
-
+
replay();
List l = new ArrayList();
@@ -241,7 +236,6 @@
trainGetEngine(cycle, engine);
trainGetOutputEncoding(engine, "utf-8");
- trainEncodeURL(cycle, "/context/Barney.html", "/context/Barney.html");
replay();
@@ -305,7 +299,6 @@
trainGetEngine(cycle, engine);
trainGetOutputEncoding(engine, "utf-8");
- trainEncodeURL(cycle, "/context/Barney.ext?sp=T", "/context/Barney.ext?sp=T");
replay();
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/DefaultPrimaryKeyConverterTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/DefaultPrimaryKeyConverterTest.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/DefaultPrimaryKeyConverterTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/DefaultPrimaryKeyConverterTest.java Sat Jul 8 15:04:28 2006
@@ -14,10 +14,16 @@
package org.apache.tapestry.util;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertSame;
+import static org.testng.AssertJUnit.assertTrue;
+
import java.util.List;
import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.testng.annotations.Test;
/**
@@ -27,7 +33,7 @@
* @since 4.0
*/
@Test
-public class DefaultPrimaryKeyConverterTest extends HiveMindTestCase
+public class DefaultPrimaryKeyConverterTest extends BaseComponentTestCase
{
/**
* Test the starting values of a number of properties.
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/ScriptUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/ScriptUtilsTest.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/ScriptUtilsTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/ScriptUtilsTest.java Sat Jul 8 15:04:28 2006
@@ -13,9 +13,14 @@
// limitations under the License.
package org.apache.tapestry.util;
-import org.apache.hivemind.test.HiveMindTestCase;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
import org.apache.oro.text.perl.Perl5Util;
import org.apache.oro.text.regex.MatchResult;
+import org.apache.tapestry.BaseComponentTestCase;
import org.testng.annotations.Test;
@@ -25,7 +30,7 @@
* @author jkuhnert
*/
@Test
-public class ScriptUtilsTest extends HiveMindTestCase
+public class ScriptUtilsTest extends BaseComponentTestCase
{
protected static final String JAVASCRIPT_NOCOMMENT =
"<script type=\"text/javascript\">"
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/StrftimeTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/StrftimeTest.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/StrftimeTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/StrftimeTest.java Sat Jul 8 15:04:28 2006
@@ -13,7 +13,9 @@
// limitations under the License.
package org.apache.tapestry.util;
-import org.apache.hivemind.test.HiveMindTestCase;
+import static org.testng.AssertJUnit.assertEquals;
+
+import org.apache.tapestry.BaseComponentTestCase;
import org.testng.annotations.Test;
@@ -24,7 +26,7 @@
* @author jkuhnert
*/
@Test
-public class StrftimeTest extends HiveMindTestCase
+public class StrftimeTest extends BaseComponentTestCase
{
public void testPosixFormat()
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestQueryParameterMap.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestQueryParameterMap.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestQueryParameterMap.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestQueryParameterMap.java Sat Jul 8 15:04:28 2006
@@ -14,10 +14,13 @@
package org.apache.tapestry.util;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+
import java.util.HashMap;
import java.util.Map;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.testng.annotations.Test;
/**
@@ -27,7 +30,7 @@
* @since 4.0
*/
@Test
-public class TestQueryParameterMap extends HiveMindTestCase
+public class TestQueryParameterMap extends BaseComponentTestCase
{
public void testUnknownKey()
{
@@ -44,7 +47,7 @@
m.setParameterValue("fred", "flintstone");
assertEquals("flintstone", m.getParameterValue("fred"));
- assertListsEqual(new String[]
+ assertListEquals(new String[]
{ "flintstone" }, m.getParameterValues("fred"));
}
@@ -57,11 +60,11 @@
m.setParameterValues("flintstone", values);
- assertListsEqual(values, m.getParameterValues("flintstone"));
+ assertListEquals(values, m.getParameterValues("flintstone"));
m.setParameterValue("rubble", "barney");
- assertListsEqual(new String[]
+ assertListEquals(new String[]
{ "barney" }, m.getParameterValues("rubble"));
}
@@ -72,7 +75,7 @@
m.setParameterValue("fred", "flintstone");
m.setParameterValue("barney", "rubble");
- assertListsEqual(new String[]
+ assertListEquals(new String[]
{ "barney", "fred" }, m.getParameterNames());
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestIntValidator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestIntValidator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestIntValidator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestIntValidator.java Sat Jul 8 15:04:28 2006
@@ -97,7 +97,7 @@
}
catch (ValidatorException ex)
{
- assertEquals("BamBam must be a numeric value.", ex.getMessage());
+ assertEquals("BamBam must be a numeric value. Format is {1}.", ex.getMessage());
assertSame(ValidationConstraint.NUMBER_FORMAT, ex.getConstraint());
}
}
@@ -154,7 +154,7 @@
assertEquals(1, map.size());
- assertEquals("Fred must be an integer value.", map.get("formatMessage"));
+ assertEquals("Fred must be an integer value. Format is {1}.", map.get("formatMessage"));
verify();
}
@@ -172,7 +172,7 @@
assertEquals(2, map.size());
assertEquals("You must enter a value for Barney.", map.get("requiredMessage"));
- assertEquals("Barney must be an integer value.", map.get("formatMessage"));
+ assertEquals("Barney must be an integer value. Format is {1}.", map.get("formatMessage"));
verify();
}
@@ -192,7 +192,7 @@
assertEquals(new Integer(5), map.get("minimum"));
assertNull(map.get("maximum"));
assertEquals("Barney must not be smaller than 5.", map.get("rangeMessage"));
- assertEquals("Barney must be an integer value.", map.get("formatMessage"));
+ assertEquals("Barney must be an integer value. Format is {1}.", map.get("formatMessage"));
verify();
}
@@ -212,7 +212,7 @@
assertEquals(new Integer(5), map.get("maximum"));
assertNull(map.get("minimum"));
assertEquals("Barney must not be larger than 5.", map.get("rangeMessage"));
- assertEquals("Barney must be an integer value.", map.get("formatMessage"));
+ assertEquals("Barney must be an integer value. Format is {1}.", map.get("formatMessage"));
verify();
}
@@ -232,7 +232,7 @@
assertEquals(new Integer(1), map.get("minimum"));
assertEquals(new Integer(5), map.get("maximum"));
assertEquals("Barney must be between 1 and 5.", map.get("rangeMessage"));
- assertEquals("Barney must be an integer value.", map.get("formatMessage"));
+ assertEquals("Barney must be an integer value. Format is {1}.", map.get("formatMessage"));
verify();
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestNumberValidator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestNumberValidator.java?rev=420205&r1=420204&r2=420205&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestNumberValidator.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/valid/TestNumberValidator.java Sat Jul 8 15:04:28 2006
@@ -226,7 +226,7 @@
}
catch (ValidatorException ex)
{
- assertEquals("invalidFormat must be a numeric value.", ex.getMessage());
+ assertEquals("invalidFormat must be a numeric value. Format is {1}.", ex.getMessage());
assertEquals(ValidationConstraint.NUMBER_FORMAT, ex.getConstraint());
}