Revision: 346
Author: tfenne
Date: 2006-07-08 12:07:30 -0700 (Sat, 08 Jul 2006)
ViewCVS: http://svn.sourceforge.net/stripes/?rev=346&view=rev
Log Message:
-----------
Fix for STS-151: ability for options-collection to localize labels.
Modified Paths:
--------------
trunk/stripes/resources/stripes.tld
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
Modified: trunk/stripes/resources/stripes.tld
===================================================================
--- trunk/stripes/resources/stripes.tld 2006-07-08 17:31:10 UTC (rev 345)
+++ trunk/stripes/resources/stripes.tld 2006-07-08 19:07:30 UTC (rev 346)
@@ -1042,6 +1042,29 @@
through that collection calling getCatId() and getName() on each
cat to produce
HTML option tags.</p>
+ <p>The tag will attempt to localize the labels attributes of the
option tags that are
+ generated. To do this it will look up labels in the field resource
bundle using:</p>
+
+ <ul>
+ <li>{className}.{labelPropertyValue}</li>
+ <li>{packageName}.{className}.{labelPropertyValue}</li>
+ <li>{className}.{valuePropertyValue}</li>
+ <li>{packageName}.{className}.{valuePropertyValue}</li>
+ </ul>
+
+ <p>For example for a class com.myco.Gender supplied to the
options-collection tag with
+ label="key" and value="description", when rendering for an instance
+ Gender[key="M", description="Male"] the following localized
properites will be looked for:
+
+ <ul>
+ <li>Gender.Male</li>
+ <li>com.myco.Gender.Male</li>
+ <li>Gender.M</li>
+ <li>com.myco.Gender.M</li>
+ </ul>
+
+ <p>If no localized label can be found then the value of the label
property will be used.</p>
+
<p>All other attributes on the tag (other than collection, value
and label) are passed
directly through to the stripes:option tag which is used to
generate the individual
HTML options tags. As a result the stripes:options-collection will
exhibit the
Modified:
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-07-08 17:31:10 UTC (rev 345)
+++
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-07-08 19:07:30 UTC (rev 346)
@@ -14,13 +14,15 @@
*/
package net.sourceforge.stripes.tag;
+import net.sourceforge.stripes.exception.StripesJspException;
import net.sourceforge.stripes.util.OgnlUtil;
-import net.sourceforge.stripes.exception.StripesJspException;
+import net.sourceforge.stripes.localization.LocalizationUtility;
import ognl.OgnlException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import java.util.Collection;
+import java.util.Locale;
/**
* <p>Writes a set of [EMAIL PROTECTED] <option value="foo">bar</option>} tags
to the page based on the
@@ -36,6 +38,29 @@
* scopes and set it on the tag. The tag would then proceed to iterate
through that collection
* calling getCatId() and getName() on each cat to produce HTML option
tags.</p>
*
+ * <p>The tag will attempt to localize the labels attributes of the option
tags that are
+ * generated. To do this it will look up labels in the field resource bundle
using:</p>
+ *
+ * <ul>
+ * <li>{className}.{labelPropertyValue}</li>
+ * <li>{packageName}.{className}.{labelPropertyValue}</li>
+ * <li>{className}.{valuePropertyValue}</li>
+ * <li>{packageName}.{className}.{valuePropertyValue}</li>
+ * </ul>
+ *
+ * <p>For example for a class com.myco.Gender supplied to the
options-collection tag with
+ * label="key" and value="description", when rendering for an instance
+ * Gender[key="M", description="Male"] the following localized properites will
be looked for:
+ *
+ * <ul>
+ * <li>Gender.Male</li>
+ * <li>com.myco.Gender.Male</li>
+ * <li>Gender.M</li>
+ * <li>com.myco.Gender.M</li>
+ * </ul>
+ *
+ * <p>If no localized label can be found then the value of the label property
will be used.</p>
+ *
* <p>All other attributes on the tag (other than collection, value and label)
are passed directly
* through to the InputOptionTag which is used to generate the individual HTML
options tags. As a
* result the InputOptionsCollectionTag will exhibit the same
re-population/selection behaviour
@@ -104,6 +129,7 @@
String labelProperty = getLabel();
String valueProperty = getValue();
+ Locale locale = getPageContext().getRequest().getLocale();
InputOptionTag tag = new InputOptionTag();
tag.setParent(this);
tag.setPageContext(getPageContext());
@@ -111,21 +137,23 @@
try {
for (Object item : this.collection) {
- Object label = null;
- if (labelProperty != null) {
- label = OgnlUtil.getValue(labelProperty, item);
- }
- else {
- label = item;
- }
+ Class clazz = item.getClass();
- Object value = null;
- if (valueProperty != null) {
- value = OgnlUtil.getValue(valueProperty, item);
+ // Lookup the bean properties for the label and value
+ Object label = (labelProperty == null) ? item :
OgnlUtil.getValue(labelProperty, item);
+ Object value = (valueProperty == null) ? item :
OgnlUtil.getValue(valueProperty, item);
+
+ // Try to localize the label
+ String localizedLabel = null;
+ if (label != null) {
+ localizedLabel = LocalizationUtility.getLocalizedFieldName
+ (clazz.getSimpleName() + "." + label,
clazz.getPackage().getName(), locale);
}
- else {
- value = item;
+ if (localizedLabel == null && value != null) {
+ localizedLabel = LocalizationUtility.getLocalizedFieldName
+ (clazz.getSimpleName() + "." + value,
clazz.getPackage().getName(), locale);
}
+ if (localizedLabel != null) label = localizedLabel;
tag.setLabel(label.toString());
tag.setValue(value);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development