Author: sergeyhalipov
Date: 2008-03-20 11:54:41 -0400 (Thu, 20 Mar 2008)
New Revision: 7015
Modified:
trunk/ui/calendar/src/main/config/component/calendar.xml
trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
Log:
http://jira.jboss.com/jira/browse/RF-2269
Modified: trunk/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/ui/calendar/src/main/config/component/calendar.xml 2008-03-20 15:45:44 UTC (rev
7014)
+++ trunk/ui/calendar/src/main/config/component/calendar.xml 2008-03-20 15:54:41 UTC (rev
7015)
@@ -565,6 +565,21 @@
If false Calendar's footer should not be shown
</description>
<defaultvalue>true</defaultvalue>
+ </property>
+ <property>
+ <name>firstWeekDay</name>
+ <classname>int</classname>
+ <description>Gets what the first day of the week is; e.g., SUNDAY in the U.S.,
MONDAY in France.</description>
+ </property>
+ <property>
+ <name>minDaysInFirstWeek</name>
+ <classname>int</classname>
+ <description>
+ Gets what the minimal days required in the first week of the year
+ are; e.g., if the first week is defined as one that contains the first
+ day of the first month of a year, this method returns 1. If the
+ minimal days required must be a full week, this method returns 7.
+ </description>
</property>
</component>
Modified: trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
--- trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2008-03-20
15:45:44 UTC (rev 7014)
+++ trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2008-03-20
15:54:41 UTC (rev 7015)
@@ -29,6 +29,8 @@
import java.util.Locale;
import java.util.TimeZone;
+import javax.el.ELException;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
@@ -74,6 +76,12 @@
public static final String CLIENT_MODE = "client";
private final static Log log = LogFactory.getLog(UICalendar.class);
+
+ private int firstWeekDay;
+ private boolean firstWeekDaySet = false;
+
+ private int minDaysInFirstWeek;
+ private boolean minDaysInFirstWeekSet = false;
public abstract Object getLocale();
@@ -615,4 +623,70 @@
}
}
+ public int getFirstWeekDay() {
+ if (this.firstWeekDaySet) {
+ return this.firstWeekDay;
+ } else {
+ Calendar cal = getCalendar();
+ int defaultValue = cal.getFirstDayOfWeek() -
cal.getActualMinimum(Calendar.DAY_OF_WEEK);
+
+ ValueExpression ve = getValueExpression("firstWeekDay");
+ if (ve != null) {
+ Integer value = null;
+
+ try {
+ value = (Integer) ve.getValue(getFacesContext().getELContext());
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+
+ if (null == value) {
+ return defaultValue;
+ }
+
+ return value.intValue();
+ } else {
+ return defaultValue;
+ }
+ }
+ }
+
+ public void setFirstWeekDay(int firstWeekDay) {
+ this.firstWeekDay = firstWeekDay;
+ this.firstWeekDaySet = true;
+ }
+
+ public int getMinDaysInFirstWeek() {
+ if (this.minDaysInFirstWeekSet) {
+ return this.minDaysInFirstWeek;
+ } else {
+ Calendar cal = getCalendar();
+ int defaultValue = cal.getMinimalDaysInFirstWeek();
+
+ ValueExpression ve = getValueExpression("minDaysInFirstWeek");
+ if (ve != null) {
+ Integer value = null;
+
+ try {
+ value = (Integer) ve.getValue(getFacesContext().getELContext());
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+
+ if (null == value) {
+ return defaultValue;
+ }
+
+ return value.intValue();
+ } else {
+ return defaultValue;
+ }
+ }
+ }
+
+ public void setMinDaysInFirstWeek(int minDaysInFirstWeek) {
+ this.minDaysInFirstWeek = minDaysInFirstWeek;
+ this.minDaysInFirstWeekSet = true;
+ }
+
}
Modified:
trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2008-03-20
15:45:44 UTC (rev 7014)
+++
trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2008-03-20
15:54:41 UTC (rev 7015)
@@ -442,15 +442,12 @@
public String getFirstWeekDay(FacesContext context, UICalendar calendar)
throws IOException {
- Calendar cal = calendar.getCalendar();
- return String.valueOf(cal.getFirstDayOfWeek()
- - cal.getActualMinimum(Calendar.DAY_OF_WEEK));
+ return String.valueOf(calendar.getFirstWeekDay());
}
public String getMinDaysInFirstWeek(FacesContext context,
UICalendar calendar) throws IOException {
- Calendar cal = calendar.getCalendar();
- return String.valueOf(cal.getMinimalDaysInFirstWeek());
+ return String.valueOf(calendar.getMinDaysInFirstWeek());
}
public String getCurrentDateAsString(FacesContext context,