Author: abelevich
Date: 2011-01-14 12:52:23 -0500 (Fri, 14 Jan 2011)
New Revision: 21038
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/utils/CalendarHelper.java
trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
trunk/ui/input/ui/src/main/templates/calendar.template.xml
Log:
RF-10094 Inline default values: input components I
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2011-01-14
17:40:58 UTC (rev 21037)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2011-01-14
17:52:23 UTC (rev 21038)
@@ -77,13 +77,13 @@
@Attribute(literal = false)
public abstract Object getFetchValue();
- @Attribute(defaultValue = "1")
+ @Attribute
public abstract int getMinChars();
@Attribute
public abstract String getFilterFunction();
- @Attribute(defaultValue = "rf-au-sel")
+ @Attribute
public abstract String getSelectedItemClass();
@Attribute
@@ -101,10 +101,10 @@
@Attribute(defaultValue = "true")
public abstract boolean isAutofill();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isDisabled();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isShowButton();
@Attribute(defaultValue = "true")
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-01-14
17:40:58 UTC (rev 21037)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-01-14
17:52:23 UTC (rev 21038)
@@ -88,26 +88,26 @@
locale
}
- public enum Modes {
+ public enum Mode {
client,
ajax
}
private Object submittedCurrentDate = null;
- @Attribute(defaultValue = "MMM d, yyyy")
+ @Attribute
public abstract String getDatePattern();
- @Attribute(defaultValue = "TimeZone.getDefault()")
+ @Attribute
public abstract TimeZone getTimeZone();
- @Attribute(defaultValue = "Integer.MIN_VALUE")
+ @Attribute
public abstract int getFirstWeekDay();
- @Attribute(defaultValue = "Integer.MIN_VALUE")
+ @Attribute
public abstract int getMinDaysInFirstWeek();
- @Attribute(defaultValue = "select")
+ @Attribute
public abstract String getTodayControlMode();
@Attribute(defaultValue = "true")
@@ -129,43 +129,43 @@
public abstract boolean isPopup();
@Attribute(defaultValue = "true")
- public abstract String getHidePopupOnScroll();
+ public abstract boolean isHidePopupOnScroll();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isDisabled();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isEnableManualInput();
@Attribute
public abstract String getDayDisableFunction();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isShowApplyButton();
- @Attribute(defaultValue = "false")
+ @Attribute
public abstract boolean isResetTimeOnDateSelect();
- @Attribute(defaultValue = "AA")
+ @Attribute
public abstract String getJointPoint();
- @Attribute(defaultValue = "AA")
+ @Attribute
public abstract String getDirection();
- @Attribute(defaultValue = "inactive")
+ @Attribute
public abstract String getBoundaryDatesMode();
- @Attribute(defaultValue = "0")
+ @Attribute
public abstract int getHorizontalOffset();
- @Attribute(defaultValue = "0")
+ @Attribute
public abstract int getVerticalOffset();
- @Attribute(defaultValue = "3")
+ @Attribute
public abstract int getZindex();
- @Attribute(defaultValue = "client")
- public abstract String getMode();
+ @Attribute
+ public abstract Mode getMode();
@Attribute
public abstract String getDefaultLabel();
@@ -218,15 +218,15 @@
@Attribute
public abstract String getButtonIconDisabled();
- @Attribute(defaultValue = "getDefaultValueOfDefaultTime(null,null)")
+ @Attribute
public abstract Object getDefaultTime();
- @Attribute(defaultValue =
"getDefaultPreloadBegin(getCurrentDateOrDefault())")
+ @Attribute
public abstract Object getPreloadDateRangeBegin();
public abstract void setPreloadDateRangeBegin(Object date);
- @Attribute(defaultValue =
"getDefaultPreloadEnd(getCurrentDateOrDefault())")
+ @Attribute
public abstract Object getPreloadDateRangeEnd();
public abstract void setPreloadDateRangeEnd(Object date);
@@ -387,7 +387,7 @@
if (ve.getType(elContext).equals(String.class)) {
DateTimeConverter convert = new DateTimeConverter();
convert.setLocale(CalendarHelper.getAsLocale(facesContext, this,
getLocale()));
- convert.setPattern(getDatePattern());
+ convert.setPattern(CalendarHelper.getDatePatternOrDefault(this));
ve.setValue(facesContext.getELContext(),
convert.getAsString(facesContext, this, currentDate));
return;
} else if (ve.getType(elContext).equals(Calendar.class)) {
@@ -442,7 +442,7 @@
protected Date getDefaultPreloadBegin(Date date) {
FacesContext facesContext = FacesContext.getCurrentInstance();
- Calendar calendar = Calendar.getInstance(getTimeZone(),
+ Calendar calendar =
Calendar.getInstance(CalendarHelper.getTimeZoneOrDefault(this),
CalendarHelper.getAsLocale(facesContext, this, getLocale()));
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
@@ -451,7 +451,7 @@
protected Date getDefaultPreloadEnd(Date date) {
FacesContext facesContext = FacesContext.getCurrentInstance();
- Calendar calendar = Calendar.getInstance(getTimeZone(),
+ Calendar calendar =
Calendar.getInstance(CalendarHelper.getTimeZoneOrDefault(this),
CalendarHelper.getAsLocale(facesContext, this, getLocale()));
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
@@ -474,7 +474,7 @@
if (value != null) {
return value;
} else {
- return java.util.Calendar.getInstance(getTimeZone()).getTime();
+ return
java.util.Calendar.getInstance(CalendarHelper.getTimeZoneOrDefault(this)).getTime();
}
}
}
@@ -592,14 +592,29 @@
Date dateRangeBegin = null;
Date dateRangeEnd = null;
- if (Modes.ajax.toString().equalsIgnoreCase(getMode())) {
+ Mode mode = getMode();
+ if (mode == null) {
+ mode = Mode.client;
+ }
+
+ if (Mode.ajax.equals(mode)) {
dateRangeBegin = CalendarHelper.getAsDate(facesContext, this,
getDefaultPreloadBegin((Date) getCurrentDateOrDefault()));
dateRangeEnd = CalendarHelper.getAsDate(facesContext, this,
getDefaultPreloadEnd((Date) getCurrentDateOrDefault()));
} else {
- dateRangeBegin = CalendarHelper.getAsDate(facesContext, this,
getPreloadDateRangeBegin());
- dateRangeEnd = CalendarHelper.getAsDate(facesContext, this,
getPreloadDateRangeEnd());
+
+ Object date = getPreloadDateRangeBegin();
+ if (date == null) {
+ date = getDefaultPreloadBegin(getCurrentDateOrDefault());
+ }
+ dateRangeBegin = CalendarHelper.getAsDate(facesContext, this, date);
+
+ date = getPreloadDateRangeEnd();
+ if (date == null) {
+ date = getDefaultPreloadEnd(getCurrentDateOrDefault());
+ }
+ dateRangeEnd = CalendarHelper.getAsDate(facesContext, this, date);
}
if (dateRangeBegin == null && dateRangeEnd == null) {
@@ -616,7 +631,7 @@
List<Date> dates = new ArrayList<Date>();
- Calendar calendar = Calendar.getInstance(this.getTimeZone(),
CalendarHelper.getAsLocale(facesContext, this, this.getLocale()));
+ Calendar calendar =
Calendar.getInstance(CalendarHelper.getTimeZoneOrDefault(this),
CalendarHelper.getAsLocale(facesContext, this, this.getLocale()));
Calendar calendar2 = (Calendar) calendar.clone();
calendar.setTime(dateRangeBegin);
calendar2.setTime(dateRangeEnd);
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2011-01-14
17:40:58 UTC (rev 21037)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2011-01-14
17:52:23 UTC (rev 21038)
@@ -307,4 +307,26 @@
public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
throw new UnsupportedOperationException();
}
+
+ protected String getSelectedItemClassOrDefault(UIComponent component) {
+ String value = "";
+ if (component instanceof AbstractAutocomplete) {
+ value = ((AbstractAutocomplete) component).getSelectedItemClass();
+ if (value == null || value.length() == 0) {
+ value = "rf-au-sel";
+ }
+ }
+ return value;
+ }
+
+ protected int getMinCharsOrDefault(UIComponent component) {
+ int value = 1;
+ if (component instanceof AbstractAutocomplete) {
+ value = ((AbstractAutocomplete) component).getMinChars();
+ if (value < 1) {
+ value = 1;
+ }
+ }
+ return value;
+ }
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2011-01-14
17:40:58 UTC (rev 21037)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2011-01-14
17:52:23 UTC (rev 21038)
@@ -266,7 +266,7 @@
Object value = calendar.getValue();
date = CalendarHelper.getAsDate(facesContext, calendar, value);
if (date != null) {
- returnValue = formatSelectedDate(calendar.getTimeZone(), date);
+ returnValue =
formatSelectedDate(CalendarHelper.getTimeZoneOrDefault(calendar), date);
}
}
return returnValue;
@@ -471,7 +471,8 @@
RenderKitUtils.addToScriptHash(map, MONTH_LABELS_SHORT, monthLabelsShort);
int minDaysInFirstWeek = calendarComponent.getMinDaysInFirstWeek();
- if (minDaysInFirstWeek == Integer.MIN_VALUE) {
+
+ if (1 > minDaysInFirstWeek || minDaysInFirstWeek > 7) {
minDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
}
@@ -480,8 +481,7 @@
}
int day = calendarComponent.getFirstWeekDay();
- if (day == Integer.MIN_VALUE) {
- day = calendar.getFirstDayOfWeek();
+ if (day < 0 || 6 < day) {
day = calendar.getFirstDayOfWeek() -
calendar.getActualMinimum(Calendar.DAY_OF_WEEK);
}
@@ -507,7 +507,12 @@
public String getStyleWithZindex(FacesContext facesContext, UIComponent component) {
AbstractCalendar calendar = (AbstractCalendar) component;
- String style = HtmlUtil.concatStyles("z-index: " +
calendar.getZindex(), calendar.getStyle());
+ int zindex = calendar.getZindex();
+ if (zindex < 0) {
+ zindex = 3;
+ }
+
+ String style = HtmlUtil.concatStyles("z-index: " + zindex,
calendar.getStyle());
return style;
}
@@ -541,9 +546,9 @@
if (converter instanceof DateTimeConverter) {
DateTimeConverter defaultConverter = (DateTimeConverter) converter;
- defaultConverter.setPattern(calendar.getDatePattern());
+
defaultConverter.setPattern(CalendarHelper.getDatePatternOrDefault(calendar));
defaultConverter.setLocale( CalendarHelper.getAsLocale(facesContext,
calendar));
- defaultConverter.setTimeZone(calendar.getTimeZone());
+ defaultConverter.setTimeZone(CalendarHelper.getTimeZoneOrDefault(calendar));
}
return converter;
}
@@ -564,4 +569,48 @@
public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
throw new UnsupportedOperationException();
}
+
+ protected String getTodayControlModeOrDefault(UIComponent component) {
+ String value = "";
+ if (component instanceof AbstractCalendar) {
+ value = ((AbstractCalendar) component).getTodayControlMode();
+ if (value == null || value.length() == 0) {
+ value = "select";
+ }
+ }
+ return value;
+ }
+
+ protected String getJointPointOrDefault(UIComponent component) {
+ String value = "";
+ if (component instanceof AbstractCalendar) {
+ value = ((AbstractCalendar) component).getJointPoint();
+ if (value == null || value.length() == 0) {
+ value = "AA";
+ }
+ }
+ return value;
+ }
+
+ protected String getDirectionOrDefault(UIComponent component) {
+ String value = "";
+ if (component instanceof AbstractCalendar) {
+ value = ((AbstractCalendar) component).getDirection();
+ if (value == null || value.length() == 0) {
+ value = "AA";
+ }
+ }
+ return value;
+ }
+
+ protected String getBoundaryDatesModeOrDefault(UIComponent component) {
+ String value = "";
+ if (component instanceof AbstractCalendar) {
+ value = ((AbstractCalendar) component).getBoundaryDatesMode();
+ if (value == null || value.length() == 0) {
+ value = "inactive";
+ }
+ }
+ return value;
+ }
}
\ No newline at end of file
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/utils/CalendarHelper.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/utils/CalendarHelper.java 2011-01-14
17:40:58 UTC (rev 21037)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/utils/CalendarHelper.java 2011-01-14
17:52:23 UTC (rev 21038)
@@ -28,6 +28,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -80,6 +81,9 @@
}
Object defaultTime = calendar.getDefaultTime();
+ if (defaultTime == null) {
+ defaultTime = AbstractCalendar.getDefaultValueOfDefaultTime(null,null);
+ }
Date result = null;
if (defaultTime instanceof Calendar) {
@@ -90,7 +94,7 @@
} else {
String defaultTimeString = defaultTime.toString();
- String datePattern = calendar.getDatePattern();
+ String datePattern = getDatePatternOrDefault(calendar);
Pattern pattern = Pattern.compile(AbstractCalendar.SUB_TIME_PATTERN);
Matcher matcher = pattern.matcher(datePattern);
@@ -194,14 +198,14 @@
if (calendar == null || facesContext == null) {
return Calendar.getInstance();
}
- return Calendar.getInstance(calendar.getTimeZone(), getAsLocale(facesContext,
calendar));
+ return Calendar.getInstance(getTimeZoneOrDefault(calendar),
getAsLocale(facesContext, calendar));
}
public static Date convertStringToDate(FacesContext facesContext, AbstractCalendar
calendar, String date) {
DateTimeConverter converter = new DateTimeConverter();
- converter.setPattern(calendar.getDatePattern());
+ converter.setPattern(getDatePatternOrDefault(calendar));
converter.setLocale(getAsLocale(facesContext, calendar));
- converter.setTimeZone(calendar.getTimeZone());
+ converter.setTimeZone(getTimeZoneOrDefault(calendar));
return (Date) converter.getAsObject(facesContext, calendar, date);
}
@@ -220,4 +224,20 @@
}
return date;
}
+
+ public static TimeZone getTimeZoneOrDefault(AbstractCalendar calendar) {
+ TimeZone value = calendar.getTimeZone();
+ if (value == null) {
+ value = TimeZone.getDefault();
+ }
+ return value;
+ }
+
+ public static String getDatePatternOrDefault(AbstractCalendar calendar) {
+ String value = calendar.getDatePattern();
+ if (value == null || "".equals(value)) {
+ value = "MMM d, yyyy";
+ }
+ return value;
+ }
}
Modified: trunk/ui/input/ui/src/main/templates/autocomplete.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-01-14 17:40:58 UTC
(rev 21037)
+++ trunk/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-01-14 17:52:23 UTC
(rev 21038)
@@ -74,8 +74,10 @@
<cdk:object name="mode" type="Object"
value="#{component.attributes['mode']}" />
<cdk:scriptObject name="options">
<cdk:scriptOption name="buttonId"
value="#{clientId}Button" />
- <cdk:scriptOption attributes="selectedItemClass minChars
filterFunction autofill disabled selectFirst tokens" />
- <cdk:scriptOption attributes="onbegin oncomplete onerror
onbeforedomupdate onchange onselectitem onfocus onblur"
wrapper="eventHandler"/>
+ <cdk:scriptOption attributes="filterFunction autofill
disabled selectFirst tokens" />
+ <cdk:scriptOption attributes="onbegin oncomplete onerror
onbeforedomupdate onchange onselectitem onfocus onblur"
wrapper="eventHandler"/>
+ <cdk:scriptOption name="minChars"
value="#{getMinCharsOrDefault(component)}" />
+ <cdk:scriptOption name="selectedItemClass"
value="#{getSelectedItemClassOrDefault(component)}" />
<cdk:scriptOption name="filterFunction"
value="#{getClientFilterFunction(component)}" />
<cdk:scriptOption name="isCachedAjax"
value="#{'ajax'==mode ? false : true}" defaultValue="true"
/>
<cdk:scriptOption name="ajaxMode"
value="#{'client'==mode||'lazyClient'==mode ? false : true}"
defaultValue="true" />
Modified: trunk/ui/input/ui/src/main/templates/calendar.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/calendar.template.xml 2011-01-14 17:40:58 UTC
(rev 21037)
+++ trunk/ui/input/ui/src/main/templates/calendar.template.xml 2011-01-14 17:52:23 UTC
(rev 21038)
@@ -69,8 +69,12 @@
<script type="text/javascript">
<cdk:scriptObject name="options">
- <cdk:scriptOption attributes="enableManualInput disabled readonly
resetTimeOnDateSelect showApplyButton popup showInput showHeader showFooter showWeeksBar
todayControlMode datePattern jointPoint direction boundaryDatesMode horizontalOffset
verticalOffset hidePopupOnScrol showWeekDaysBar styleClass mode defaultLabel" />
- <cdk:scriptOption attributes="onchange ondateselect onbeforedateselect
onbeforecurrentdateselect onhide onshow ondatemouseover ondatemouseout onclean
ontimeselect onbeforetimeselect" wrapper="eventHandler" />
+ <cdk:scriptOption attributes="enableManualInput disabled readonly
resetTimeOnDateSelect showApplyButton popup showInput showHeader showFooter showWeeksBar
datePattern horizontalOffset verticalOffset hidePopupOnScrol showWeekDaysBar styleClass
mode defaultLabel" />
+ <cdk:scriptOption attributes="onchange ondateselect onbeforedateselect
onbeforecurrentdateselect onhide onshow ondatemouseover ondatemouseout onclean
ontimeselect onbeforetimeselect" wrapper="eventHandler" />
+ <cdk:scriptOption name="todayControlMode"
value="#{getTodayControlModeOrDefault(component)}" />
+ <cdk:scriptOption name="jointPoint"
value="#{getJointPointOrDefault(component)}" />
+ <cdk:scriptOption name="direction"
value="#{getDirectionOrDefault(component)}" />
+ <cdk:scriptOption name="boundaryDatesMode"
value="#{getBoundaryDatesModeOrDefault(component)}" />
<cdk:scriptOption name="currentDate"
value="#{getCurrentDate(facesContext, component)}" />
<cdk:scriptOption name="selectedDate"
value="#{getSelectedDate(facesContext, component)}" />
<cdk:scriptOption name="dayCellClass"
value="#{getDayCellClass(facesContext, component)}" />