[seam-commits] Seam SVN: r10761 - in examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking: reference and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 4 00:33:25 EDT 2009
Author: dan.j.allen
Date: 2009-05-04 00:33:25 -0400 (Mon, 04 May 2009)
New Revision: 10761
Added:
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java
examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/Month.java
Log:
use producer methods for reference data to back <f:selectItems>
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CalendarReferenceProducer.java 2009-05-04 04:33:25 UTC (rev 10761)
@@ -0,0 +1,59 @@
+package org.jboss.seam.examples.booking.reference;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Locale;
+import javax.annotation.Named;
+import javax.context.ConversationScoped;
+import javax.inject.Current;
+import javax.inject.Produces;
+
+/**
+ * Produces calendar-oriented reference data to be used in user-interface forms.
+ * The user's locale is honored when producing name-based data.
+ *
+ * @author Dan Allen
+ */
+public class CalendarReferenceProducer {
+
+ @Current Locale locale;
+
+ public
+ @Produces
+ @Named
+ @ConversationScoped
+ List<Month> getMonths()
+ {
+ List<Month> months = new ArrayList<Month>(12);
+ DateFormat longNameFormat = new SimpleDateFormat("MMMM", locale);
+ DateFormat shortNameFormat = new SimpleDateFormat("MMM", locale);
+ Calendar cal = Calendar.getInstance();
+ for (int m = 0; m < 12; m++)
+ {
+ cal.set(Calendar.MONTH, m);
+ months.add(new Month(m, longNameFormat.format(cal.getTime()), shortNameFormat.format(cal.getTime())));
+ }
+
+ return months;
+ }
+
+ public
+ @Produces
+ @Named
+ @ConversationScoped
+ @CreditCardExpiryYears
+ List<Integer> getCreditCardExpiryYears()
+ {
+ List<Integer> years = new ArrayList<Integer>(8);
+ int currentYear = Calendar.getInstance().get(Calendar.YEAR);
+ for (int y = currentYear; y <= (currentYear + 8); y++)
+ {
+ years.add(y);
+ }
+
+ return years;
+ }
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/CreditCardExpiryYears.java 2009-05-04 04:33:25 UTC (rev 10761)
@@ -0,0 +1,33 @@
+package org.jboss.seam.examples.booking.reference;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.inject.BindingType;
+
+/**
+ * A binding type attached to a collection of years
+ * indicating the set is limited to the possible
+ * values for a credit card expiry date.
+ *
+ * @author Dan Allen
+ */
+public
+ at Target(
+{
+ METHOD, PARAMETER, FIELD
+})
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+ at Inherited
+ at interface CreditCardExpiryYears
+{
+}
Added: examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/Month.java
===================================================================
--- examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/Month.java (rev 0)
+++ examples/trunk/booking/ejb-jar/src/main/java/org/jboss/seam/examples/booking/reference/Month.java 2009-05-04 04:33:25 UTC (rev 10761)
@@ -0,0 +1,49 @@
+package org.jboss.seam.examples.booking.reference;
+
+/**
+ * A simple Java bean representing a month. This
+ * bean assumes that the names it is provided
+ * have already been localized.
+ *
+ * @author Dan Allen
+ */
+public class Month {
+
+ private int index;
+ private String name;
+ private String shortName;
+
+ public Month() {}
+
+ public Month(int index, String name, String shortName)
+ {
+ this.index = index;
+ this.name = name;
+ this.shortName = shortName;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public int getNumber()
+ {
+ return index + 1;
+ }
+
+ public String getLongName()
+ {
+ return name;
+ }
+
+ public String getShortName()
+ {
+ return shortName;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
More information about the seam-commits
mailing list