Author: sergeyhalipov
Date: 2008-04-08 15:45:38 -0400 (Tue, 08 Apr 2008)
New Revision: 7681
Modified:
trunk/ui/calendar/src/main/config/component/calendar.xml
trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
Log:
Calendar: optimize code for locale-depended attributes.
Modified: trunk/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/ui/calendar/src/main/config/component/calendar.xml 2008-04-08 17:55:41 UTC (rev
7680)
+++ trunk/ui/calendar/src/main/config/component/calendar.xml 2008-04-08 19:45:38 UTC (rev
7681)
@@ -571,6 +571,7 @@
<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>
+ <defaultvalue>getDefaultFirstWeekDay()</defaultvalue>
</property>
<property>
<name>minDaysInFirstWeek</name>
@@ -581,6 +582,7 @@
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>
+ <defaultvalue>getDefaultMinDaysInFirstWeek()</defaultvalue>
</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-04-08
17:55:41 UTC (rev 7680)
+++ trunk/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2008-04-08
19:45:38 UTC (rev 7681)
@@ -77,12 +77,6 @@
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();
public abstract void setLocale(Object locale);
@@ -211,7 +205,14 @@
public abstract boolean isShowApplyButton();
public abstract void setShowApplyButton(boolean showApplyButton);
+
+ public abstract int getFirstWeekDay();
+ public abstract void setFirstWeekDay(int firstWeekDay);
+ public abstract int getMinDaysInFirstWeek();
+ public abstract void setMinDaysInFirstWeek(int minDaysInFirstWeek);
+
+
// TODO onclick add users onclick
// currentDate processing -------------------------------------------------
@@ -623,86 +624,12 @@
}
}
- 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;
- }
- }
+ protected int getDefaultFirstWeekDay() {
+ Calendar cal = getCalendar();
+ return cal.getFirstDayOfWeek() - cal.getActualMinimum(Calendar.DAY_OF_WEEK);
}
-
- 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;
- }
- public Object saveState(FacesContext context) {
- Object[] state = new Object[3];
- state[0] = super.saveState(context);
- state[1] = new Integer(this.firstWeekDay);
- state[2] = new Integer(this.minDaysInFirstWeek);
-
- return state;
+ protected int getDefaultMinDaysInFirstWeek() {
+ return getCalendar().getMinimalDaysInFirstWeek();
}
-
- public void restoreState(FacesContext context, Object state) {
- Object[] _state = (Object[]) state;
- super.restoreState(context, _state[0]);
- this.firstWeekDay = ((Integer)_state[1]).intValue();
- this.minDaysInFirstWeek = ((Integer)_state[2]).intValue();
- }
-
}
Show replies by date