Revision: 784
http://stripes.svn.sourceforge.net/stripes/?rev=784&view=rev
Author: bengunter
Date: 2008-01-20 21:03:12 -0800 (Sun, 20 Jan 2008)
Log Message:
-----------
Fixed STS-242. Added optional element @Validate(label="Some string") to allow
developers to easily label an ActionBean property without having to add it to
the resource bundle. If a label for the property is present in the resource
bundle, it will override this new element.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
trunk/stripes/src/net/sourceforge/stripes/validation/Validate.java
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
2008-01-21 04:45:30 UTC (rev 783)
+++
trunk/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
2008-01-21 05:03:12 UTC (rev 784)
@@ -17,6 +17,7 @@
import net.sourceforge.stripes.controller.ParameterName;
import net.sourceforge.stripes.controller.StripesFilter;
import net.sourceforge.stripes.util.Log;
+import net.sourceforge.stripes.validation.ValidationMetadata;
import net.sourceforge.stripes.config.Configuration;
import net.sourceforge.stripes.action.ActionBean;
@@ -81,12 +82,22 @@
catch (MissingResourceException mre) { /* do nothing */ }
}
- // Lastly, all by itself
+ // Then all by itself
if (localizedValue == null) {
try { localizedValue = bundle.getString(name); }
catch (MissingResourceException mre2) { /* do nothing */ }
}
+ // Lastly, check @Validate on the ActionBean property
+ if (localizedValue == null && beanclass != null) {
+ ValidationMetadata validate = StripesFilter.getConfiguration()
+ .getValidationMetadataProvider()
+ .getValidationMetadata(beanclass, name);
+ if (validate != null && validate.label() != null &&
!"".equals(validate.label())) {
+ localizedValue = validate.label();
+ }
+ }
+
return localizedValue;
}
Modified: trunk/stripes/src/net/sourceforge/stripes/validation/Validate.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/validation/Validate.java
2008-01-21 04:45:30 UTC (rev 783)
+++ trunk/stripes/src/net/sourceforge/stripes/validation/Validate.java
2008-01-21 05:03:12 UTC (rev 784)
@@ -20,6 +20,7 @@
import java.lang.annotation.ElementType;
import java.lang.annotation.Documented;
+import net.sourceforge.stripes.localization.LocalizationUtility;
import net.sourceforge.stripes.tag.InputHiddenTag;
/**
@@ -129,4 +130,13 @@
@SuppressWarnings("unchecked")
Class<? extends TypeConverter> converter() default TypeConverter.class;
+ /**
+ * The natural language name to use for the field when reporting
validation errors, generating
+ * form input labels, etc. This will only be used if a localized field
name cannot be found in
+ * the resource bundle.
+ *
+ * @see LocalizationUtility#getLocalizedFieldName(String, String, Class,
java.util.Locale)
+ */
+ String label() default "";
+
}
Modified:
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
2008-01-21 04:45:30 UTC (rev 783)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/ValidationMetadata.java
2008-01-21 05:03:12 UTC (rev 784)
@@ -44,6 +44,7 @@
private String expression;
@SuppressWarnings("unchecked")
private Class<? extends TypeConverter> converter;
+ private String label;
/**
* Constructs a ValidationMetadata object for the specified property.
Further constraints
@@ -77,6 +78,7 @@
if (validate.converter() != TypeConverter.class)
converter(validate.converter());
if (!"".equals(validate.expression()))
expression(validate.expression());
if (validate.on().length > 0) on(validate.on());
+ if (!"".equals(validate.label())) this.label = validate.label();
}
/** Returns the name of the property this validation metadata represents.
*/
@@ -207,6 +209,12 @@
return this;
}
+ /** Set the field label. */
+ public void label(String label) { this.label = label;}
+
+ /** Get the field label. */
+ public String label() { return label; }
+
/**
* Overidden toString() that only outputs the constraints that are
specified by
* the instance of validation metadata (i.e. omits nulls, defaults etc.)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development