Revision: 397
Author: tfenne
Date: 2006-08-28 18:37:44 -0700 (Mon, 28 Aug 2006)
ViewCVS: http://svn.sourceforge.net/stripes/?rev=397&view=rev
Log Message:
-----------
Merge of trunk changes from r393:396.
Modified Paths:
--------------
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
Added Paths:
-----------
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/EnumFormatter.java
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
2006-08-29 01:36:09 UTC (rev 396)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
2006-08-29 01:37:44 UTC (rev 397)
@@ -21,7 +21,7 @@
/**
* Very simple default implementation of a formatter factory that is aware of
how to format
- * dates and numbers.
+ * dates, numbers and enums.
*
* @author Tim Fennell
*/
@@ -69,6 +69,11 @@
formatter.init();
return formatter;
}
+ else if (clazz.isEnum()) {
+ formatter = new EnumFormatter();
+ formatter.init();
+ return formatter;
+ }
else {
return null;
}
Copied:
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/EnumFormatter.java
(from rev 396,
trunk/stripes/src/net/sourceforge/stripes/format/EnumFormatter.java)
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/EnumFormatter.java
(rev 0)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/format/EnumFormatter.java
2006-08-29 01:37:44 UTC (rev 397)
@@ -0,0 +1,53 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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 net.sourceforge.stripes.format;
+
+import java.util.Locale;
+
+/**
+ * A simple formatter for Enum classes that always returns the value of
Enum.name(). Intended
+ * really only to enable the seamless usage of enums as values in hidden
fields, radio
+ * buttons, checkboxes etc. it is not intended that this will be used to
format Enum
+ * values into text fields where a localized value might be more appropriate.
+ *
+ * @author Tim Fennell
+ * @since Stripes 1.4.1
+ */
+public class EnumFormatter implements Formatter<Enum> {
+ /** Does nothing. Format types are not supported for Enums. */
+ public void setFormatType(String formatType) { }
+
+ /** Does nothing. Format patterns are not supported for Enums. */
+ public void setFormatPattern(String formatPattern) { }
+
+ /** Does nothing. Enums values are always formatted using name() which is
not localizable. */
+ public void setLocale(Locale locale) { }
+
+ /** Does nothing since no initialization is needed. */
+ public void init() { }
+
+ /**
+ * Formats the supplied value as a String. If the value cannot be
formatted because it is
+ * an inappropriate type, or because faulty pattern information was
supplied, should fail
+ * loudly by throwing a RuntimeException or subclass thereof.
+ *
+ * @param input an object of a type that the formatter knows how to format
+ * @return a String version of the input, formatted for the chosen locale
+ */
+ public String format(Enum input) {
+ if (input != null) return input.name();
+ else return null;
+ }
+}
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2006-08-29 01:36:09 UTC (rev 396)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2006-08-29 01:37:44 UTC (rev 397)
@@ -96,10 +96,22 @@
clazz = (Class<Enum>) ReflectUtil.findClass(this.className);
}
catch (Exception e) {
- throw new StripesJspException
- ("Could not process class [" + this.className + "].
Attribute 'enum' on " +
- "tag options-enumeration must be the fully
qualified name of a " +
- "class which is a java 1.5 enum.", e);
+ // Try replacing the last period with a $ just in case the enum in
question
+ // is an inner class of another class
+ try {
+ int last = this.className.lastIndexOf('.');
+ if (last > 0) {
+ String n2 = new StringBuilder(className).replace(last,
last+1, "$").toString();
+ clazz = ReflectUtil.findClass(n2);
+ }
+ }
+ // If our second attempt didn't work, wrap the *original* exception
+ catch (Exception e2) {
+ throw new StripesJspException
+ ("Could not process class [" + this.className + "].
Attribute 'enum' on " +
+ "tag options-enumeration must be the fully qualified
name of a " +
+ "class which is a java 1.5 enum.", e);
+ }
}
if (!clazz.isEnum()) {
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
===================================================================
--- branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2006-08-29 01:36:09 UTC (rev 396)
+++ branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2006-08-29 01:37:44 UTC (rev 397)
@@ -381,7 +381,7 @@
JspWriter out = getPageContext().getOut();
out.write("<script type=\"text/javascript\">var
z=document.getElementById('");
out.write(getId());
- out.write("'); z.focus(); z.select();</script>");
+ out.write("'); try{z.focus(); z.select();} catch(e) {}</script>");
}
catch (IOException ioe) {
throw new StripesJspException("Could not write javascript focus
code to jsp writer.", ioe);
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