Author: amarkhel
Date: 2010-12-09 09:04:09 -0500 (Thu, 09 Dec 2010)
New Revision: 20476
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.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
Log:
https://jira.jboss.org/browse/RF-9837 Calendar: attribute defaultTime doesn't work
defaultTime attribute and time pattern is corrected
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 2010-12-09
13:51:23 UTC (rev 20475)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-12-09
14:04:09 UTC (rev 20476)
@@ -78,13 +78,11 @@
public static final String COMPONENT_FAMILY = "org.richfaces.Calendar";
- public static final String SUB_TIME_PATTERN =
"\\s*[hHkKma]+[\\W&&\\S]+[hHkKma]+\\s*";
+ public static final String SUB_TIME_PATTERN =
"\\s*[hHkKma]+[\\W&&\\S]+[hHkKma]+[\\W&&\\S]*[s]*\\s*";
- public static final String TIME_PATTERN = "HH:mm";
+ public static final String TIME_PATTERN = "HH:mm:ss";
public static final String DEFAULT_DATE_PATTERN = "MMM d, yyyy";
-
- public static final String DEFAULT_DATE_VALUE = "12:00:00";
Logger log = RichfacesLogger.COMPONENTS.getLogger();
@@ -95,9 +93,8 @@
public enum Modes {
CLIENT,
AJAX
- }
+ }
-
@Attribute(defaultValue = "MMM d, yyyy")
public abstract String getDatePattern();
@@ -218,7 +215,7 @@
@Attribute
public abstract String getButtonIconDisabled();
- @Attribute(defaultValue = "AbstractCalendar.DEFAULT_DATE_VALUE")
+ @Attribute(defaultValue = "getDefaultValueOfDefaultTime(null,null)")
public abstract Object getDefaultTime();
@Attribute(defaultValue =
"getDefaultPreloadBegin(getCurrentDateOrDefault())")
@@ -332,6 +329,8 @@
public void setLocale(Object locale) {
getStateHelper().put(PropertyKeys.locale, locale);
}
+
+
public void updateCurrentDate(FacesContext facesContext, Object currentDate) {
if (facesContext == null) {
@@ -386,6 +385,18 @@
return (CurrentDateChangeListener[])
getFacesListeners(CurrentDateChangeListener.class);
}
+ public static Object getDefaultValueOfDefaultTime(FacesContext facesContext,
AbstractCalendar calendarComponent) {
+ if (calendarComponent == null) {
+ return null;
+ }
+
+ Calendar calendar = CalendarHelper.getCalendar(facesContext, calendarComponent);
+ calendar.set(Calendar.HOUR_OF_DAY, 12);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ return calendar.getTime();
+ }
+
protected Date getDefaultPreloadBegin(Date date) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Calendar calendar = Calendar.getInstance(getTimeZone(),
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 2010-12-09
13:51:23 UTC (rev 20475)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-12-09
14:04:09 UTC (rev 20476)
@@ -407,7 +407,7 @@
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);
- if (hours != 12 || minutes != 0) {
+ if (hours != 12 || minutes != 0 || seconds != 0) {
result.put(HOURS_VALUE, hours);
result.put(MINUTES_VALUE, minutes);
result.put(SECONDS_VALUE, seconds);
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 2010-12-09
13:51:23 UTC (rev 20475)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/utils/CalendarHelper.java 2010-12-09
14:04:09 UTC (rev 20476)
@@ -75,19 +75,8 @@
}
return value;
- }
+ }
- public static Object getDefaultValueOfDefaultTime(FacesContext facesContext,
AbstractCalendar calendarComponent) {
- if (calendarComponent == null) {
- return null;
- }
-
- Calendar calendar = getCalendar(facesContext, calendarComponent);
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 0);
- return calendar.getTime();
- }
-
public static Date getFormattedDefaultTime(AbstractCalendar calendar) {
if (calendar == null || calendar.getDefaultTime() == null) {
return null;
@@ -106,12 +95,11 @@
String defaultTimeString = defaultTime.toString();
String datePattern = calendar.getDatePattern();
- String timePattern = AbstractCalendar.TIME_PATTERN;
- Pattern pattern = Pattern.compile(timePattern);
+ Pattern pattern = Pattern.compile(AbstractCalendar.SUB_TIME_PATTERN);
Matcher matcher = pattern.matcher(datePattern);
-
- String subTimePattern = AbstractCalendar.SUB_TIME_PATTERN;
- if (matcher.find()) {
+ String subTimePattern = AbstractCalendar.TIME_PATTERN;
+
+ if(matcher.find()) {
subTimePattern = matcher.group().trim();
}