Revision: 1093
http://stripes.svn.sourceforge.net/stripes/?rev=1093&view=rev
Author: bengunter
Date: 2009-03-03 16:33:59 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Fixed STS-629: The "field-metadata" tag should provide the "on" property value.
This required adding an on() method to ValidationMetadata, which should have
been there in the first place. I also fixed a potential NPE and used
JavascriptBuilder.quote to quote strings in the output.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
2009-03-03 15:22:51 UTC (rev 1092)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
2009-03-03 16:33:59 UTC (rev 1093)
@@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
@@ -14,6 +15,7 @@
import javax.servlet.jsp.tagext.BodyTag;
import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.ajax.JavaScriptBuilder;
import net.sourceforge.stripes.controller.StripesFilter;
import net.sourceforge.stripes.exception.StripesJspException;
import net.sourceforge.stripes.localization.LocalizationUtility;
@@ -143,11 +145,11 @@
StringBuilder fieldInfo = new StringBuilder();
if (fieldType.isPrimitive() ||
Number.class.isAssignableFrom(fieldType)
- || Date.class.isAssignableFrom(fieldType) || includeType)
- fieldInfo.append("type:")
- .append("'")
- .append(fqn ? fieldType.getName() :
fieldType.getSimpleName())
- .append("'");
+ || Date.class.isAssignableFrom(fieldType) || includeType) {
+ fieldInfo.append("type:").append(
+ JavaScriptBuilder.quote(fqn ? fieldType.getName() :
fieldType
+ .getSimpleName()));
+ }
Class<?> typeConverterClass = null;
@@ -158,6 +160,16 @@
if (data.required())
fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("required:").append(
data.required());
+ if (data.on() != null) {
+ fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("on:[");
+ Iterator<String> it = data.on().iterator();
+ while (it.hasNext()) {
+ fieldInfo.append(JavaScriptBuilder.quote(it.next()));
+ if (it.hasNext())
+ fieldInfo.append(",");
+ }
+ fieldInfo.append("]");
+ }
if (data.trim())
fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("trim:").append(
data.trim());
@@ -186,8 +198,8 @@
locale);
}
if (label != null)
- fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("label:")
- .append("'").append(label.replaceAll("'",
"\\\\'")).append("'");
+ fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("label:").append(
+ JavaScriptBuilder.quote(label));
typeConverterClass = data.converter();
}
@@ -206,11 +218,10 @@
}
if (typeConverterClass != null) {
- fieldInfo.append(fieldInfo.length() > 0 ? "," : "")
- .append("typeConverter:")
- .append("'")
- .append(fqn ? typeConverterClass.getName() :
typeConverterClass.getSimpleName())
- .append("'");
+ fieldInfo.append(fieldInfo.length() > 0 ? "," :
"").append("typeConverter:")
+ .append(
+ JavaScriptBuilder.quote(fqn ?
typeConverterClass.getName()
+ : typeConverterClass.getSimpleName()));
}
@@ -220,7 +231,7 @@
else
sb.append(",\r\n\t\t");
- sb.append("'").append(field).append("':{");
+ sb.append(JavaScriptBuilder.quote(field)).append(":{");
sb.append(fieldInfo);
@@ -407,9 +418,11 @@
private Var(String fieldMetadata) {
this.fieldMetadata = fieldMetadata;
FormTag form = getForm();
- if (form.getId() == null)
- form.setId("stripes-" + new Random().nextInt());
- this.formId = form.getId();
+ if (form != null) {
+ if (form.getId() == null)
+ form.setId("stripes-" + new Random().nextInt());
+ this.formId = form.getId();
+ }
}
@Override
Modified:
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
2009-03-03 15:22:51 UTC (rev 1092)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
2009-03-03 16:33:59 UTC (rev 1093)
@@ -220,6 +220,9 @@
return this;
}
+ /** Returns the set of events for which the field in question is required.
May return null. */
+ public Set<String> on() { return this.on; }
+
/** Set the field label. */
public void label(String label) { this.label = label;}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development