[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...
Norman Richards
norman.richards at jboss.com
Thu Dec 21 15:19:03 EST 2006
User: nrichards
Date: 06/12/21 15:19:03
Modified: src/ui/org/jboss/seam/ui SelectDate.java selectDate.js
Log:
JBSEAM-623: support locales for selectDate display
Revision Changes Path
1.4 +52 -2 jboss-seam/src/ui/org/jboss/seam/ui/SelectDate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SelectDate.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/SelectDate.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- SelectDate.java 14 Dec 2006 09:10:55 -0000 1.3
+++ SelectDate.java 21 Dec 2006 20:19:03 -0000 1.4
@@ -3,6 +3,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.text.DateFormatSymbols;
+import java.util.Calendar;
+import java.util.Locale;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -95,6 +98,15 @@
request.put("SELECTDATE_SCRIPT", scriptResource);
ResponseWriter response = context.getResponseWriter();
+
+ writeLocaleInformation(response, context.getViewRoot().getLocale());
+ writeScriptFromResource(response, scriptResource);
+ }
+
+ private void writeScriptFromResource(ResponseWriter response,
+ String scriptResource)
+ throws IOException
+ {
response.startElement("script", null);
response.writeAttribute("type", "text/javascript", null);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(scriptResource);
@@ -117,4 +129,42 @@
response.endElement("script");
}
+
+
+ private void writeLocaleInformation(ResponseWriter response,
+ Locale locale) throws IOException
+ {
+ response.startElement("script", null);
+ response.writeAttribute("type", "text/javascript", null);
+
+ Calendar cal = Calendar.getInstance(locale);
+ DateFormatSymbols symbols = new DateFormatSymbols(locale);
+
+ // Note: Calendar and DateFormatSymbols use 1 for the first day of the week, not 0.
+
+ response.write("\r");
+ response.write("var dayArrayShort = " + getArray(symbols.getShortWeekdays(), 1) + ";\r");
+ response.write("var dayArrayMed = " + getArray(symbols.getShortWeekdays(), 1) + ";\r");
+ response.write("var dayArrayLong = " + getArray(symbols.getWeekdays(), 1) + ";\r");
+ response.write("var monthArrayShort = " + getArray(symbols.getShortMonths(), 0) + ";\r");
+ response.write("var monthArrayMed = " + getArray(symbols.getShortMonths(), 0) + ";\r");
+ response.write("var monthArrayLong = " + getArray(symbols.getMonths(), 0) + ";\r");
+ response.write("var firstDayInWeek = " + (cal.getFirstDayOfWeek() - 1) + ";\r");
+
+ response.endElement("script");
+ }
+
+ private StringBuilder getArray(String[] values, int start) throws IOException {
+ StringBuilder s = new StringBuilder();
+ s.append("new Array(");
+ for (int i = start; i < values.length; i++) {
+ if (i > start) {
+ s.append(", ");
+ }
+ s.append("'").append(values[i]).append("'");
+ }
+ s.append(")");
+ return s;
+ }
+
}
1.3 +38 -18 jboss-seam/src/ui/org/jboss/seam/ui/selectDate.js
(In the diff below, changes in quantity of whitespace are not shown.)
Index: selectDate.js
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/selectDate.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- selectDate.js 8 Dec 2006 00:37:04 -0000 1.2
+++ selectDate.js 21 Dec 2006 20:19:03 -0000 1.3
@@ -6,12 +6,7 @@
var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";
-var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
-var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
-var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
-var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
-var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
-var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
+// text label variables generate by selectDate component
// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
@@ -129,7 +124,9 @@
var xTR = "</tr>" + crlf;
var TD = "<td class='seam-date-day' onmouseout='this.className=\"seam-date-day\";' onmouseover='this.className=\"seam-date-hover\";' "; // leave this tag open, because we'll be adding an onclick event
+ var TD_weekend = "<td class='seam-date-day weekend' onmouseout='this.className=\"seam-date-day weekend\";' onmouseover='this.className=\"seam-date-hover\";' "; // leave this tag open, because we'll be adding an onclick event
var TD_selected = "<td class='seam-date-selected' onmouseout='this.className=\"seam-date-selected\";' onmouseover='this.className=\"seam-date-hover\";' "; // leave this tag open, because we'll be adding an onclick event
+ var TD_selected_weekend = "<td class='seam-date-selected weekend' onmouseout='this.className=\"seam-date-selected weekend\";' onmouseover='this.className=\"seam-date-hover\";' "; // leave this tag open, because we'll be adding an onclick event
var TD_blank = "<td";
var TD_title = "<td colspan='5'>";
var TD_buttons = "<td>";
@@ -151,40 +148,47 @@
// this is the row that indicates which day of the week we're on
html += TR_days;
- for(i = 0; i < dayArrayShort.length; i++)
- html += TD_days + dayArrayShort[i] + xTD;
+ for(i = 0; i < 7; i++) {
+ html += TD_days + getDayName(i) + xTD;
+ }
html += xTR;
// now we'll start populating the table with days of the month
html += TR;
// first, the leading blanks
- for (i = 0; i < thisDay.getDay(); i++)
+ for (i = 0; i < getDay(thisDay.getDay()); i++) {
html += TD_blank + "> " + xTD;
+ }
// now, the days of the month
do {
dayNum = thisDay.getDate();
+ var weekend = isWeekend(thisDay.getDay());
+
TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
- if (dayNum == day)
- html += TD_selected + TD_onclick + dayNum + xTD;
- else
- html += TD + TD_onclick + dayNum + xTD;
+ if (dayNum == day) {
+ html += (weekend ? TD_selected_weekend : TD_selected) + TD_onclick + dayNum + xTD;
+ } else {
+ html += (weekend ? TD_weekend : TD) + TD_onclick + dayNum + xTD;
+ }
// if this is a Saturday, start a new row
- if (thisDay.getDay() == 6)
+ if (getDay(thisDay.getDay()) == 6) {
html += xTR + TR;
+ }
// increment the day
thisDay.setDate(thisDay.getDate() + 1);
} while (thisDay.getDate() > 1)
// fill in any trailing blanks
- if (thisDay.getDay() > 0) {
- for (i = 6; i > thisDay.getDay(); i--)
+ if (getDay(thisDay.getDay()) > 0) {
+ for (i = 7; i > getDay(thisDay.getDay()); i--) {
html += TD_blank + "> " + xTD;
}
+ }
html += xTR;
// add a button to allow the user to easily return to today, or close the calendar
@@ -204,6 +208,22 @@
}
+function getDayName(day) {
+ return dayArrayShort[(day + firstDayInWeek) % 7];
+}
+
+function getDay(day) {
+ var convertedDay = day - firstDayInWeek;
+ if (convertedDay < 0) {
+ convertedDay += 7;
+ }
+ return convertedDay;
+}
+
+function isWeekend(day) {
+ return (day == 0) || (day == 6);
+}
+
/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
More information about the jboss-cvs-commits
mailing list