Author: nbelaevski
Date: 2007-07-20 20:37:29 -0400 (Fri, 20 Jul 2007)
New Revision: 1764
Added:
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarValidator.java
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java
Removed:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CurrentDateChangeEvent.java
Modified:
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java
trunk/sandbox/samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml
trunk/sandbox/samples/calendar-sample/src/main/webapp/index.jsp
trunk/sandbox/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
trunk/sandbox/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
trunk/sandbox/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
Log:
- sample app updated
- 13/17th validator added
- draft conversion/validation implemented
Modified:
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java
===================================================================
---
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarBean.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -21,6 +21,8 @@
package org.richfaces;
+import java.text.DateFormat;
+import java.util.Date;
import java.util.Locale;
import javax.faces.event.ValueChangeEvent;
@@ -33,10 +35,14 @@
*/
public class CalendarBean {
+ private static final String[] WEEK_DAY_LABELS = new String[] {"Sun *",
"Mon +", "Tue +", "Wed +", "Thu +", "Fri
+", "Sat *"};
private Locale locale;
private boolean popup;
private String pattern;
+ private Date currentDate;
+ private Date selectedDate;
+ private boolean useCustomDayLabels;
public Locale getLocale() {
return locale;
@@ -68,7 +74,7 @@
locale = Locale.US;
popup = false;
- pattern = "d/M/yy";
+ pattern = "MMM d, yyyy";
}
public void selectLocale(ValueChangeEvent event){
@@ -78,6 +84,45 @@
String country = tLocale.substring(3);
locale = new Locale(lang,country,"");
}
+
+ public boolean isUseCustomDayLabels() {
+ return useCustomDayLabels;
+ }
+
+ public void setUseCustomDayLabels(boolean useCustomDayLabels) {
+ this.useCustomDayLabels = useCustomDayLabels;
+ }
-
+ public Object getWeekDayLabelsShort() {
+ if (isUseCustomDayLabels()) {
+ return WEEK_DAY_LABELS;
+ } else {
+ return null;
+ }
+ }
+
+ public String getCurrentDateAsText() {
+ Date currentDate = getCurrentDate();
+ if (currentDate != null) {
+ return DateFormat.getDateInstance(DateFormat.FULL).format(currentDate);
+ }
+
+ return null;
+ }
+
+ public Date getCurrentDate() {
+ return currentDate;
+ }
+
+ public void setCurrentDate(Date currentDate) {
+ this.currentDate = currentDate;
+ }
+
+ public Date getSelectedDate() {
+ return selectedDate;
+ }
+
+ public void setSelectedDate(Date selectedDate) {
+ this.selectedDate = selectedDate;
+ }
}
\ No newline at end of file
Added:
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarValidator.java
===================================================================
---
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarValidator.java
(rev 0)
+++
trunk/sandbox/samples/calendar-sample/src/main/java/org/richfaces/CalendarValidator.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -0,0 +1,40 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 21.07.2007
+ *
+ */
+public class CalendarValidator implements Validator {
+
+ /* (non-Javadoc)
+ * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.Object)
+ */
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException {
+
+ Date date = (Date) value;
+ if (date != null) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ int d = calendar.get(Calendar.DATE);
+ if (d == 13 || d == 17) {
+ throw new ValidatorException(new FacesMessage("Test validator: 13th and 17th
dates are restricted!"));
+ }
+ }
+ }
+
+}
Modified: trunk/sandbox/samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/sandbox/samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml 2007-07-21
00:37:29 UTC (rev 1764)
@@ -17,4 +17,8 @@
<managed-bean-class>org.richfaces.CalendarBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <validator>
+ <validator-id>org.richfaces.CalendarValidator</validator-id>
+ <validator-class>org.richfaces.CalendarValidator</validator-class>
+ </validator>
</faces-config>
Modified: trunk/sandbox/samples/calendar-sample/src/main/webapp/index.jsp
===================================================================
--- trunk/sandbox/samples/calendar-sample/src/main/webapp/index.jsp 2007-07-21 00:27:25
UTC (rev 1763)
+++ trunk/sandbox/samples/calendar-sample/src/main/webapp/index.jsp 2007-07-21 00:37:29
UTC (rev 1764)
@@ -5,7 +5,7 @@
<head></head>
<body>
- <jsp:forward page="/pages/index.jsf" />
+ <jsp:forward page="/pages/Calendar.jsf" />
</body>
</html>
\ No newline at end of file
Modified: trunk/sandbox/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
===================================================================
--- trunk/sandbox/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2007-07-21
00:27:25 UTC (rev 1763)
+++ trunk/sandbox/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2007-07-21
00:37:29 UTC (rev 1764)
@@ -1,39 +1,84 @@
+<%@ page pageEncoding="UTF-8" %>
+
<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/ui/calendar"
prefix="calendar" %>
+
<html>
<head>
<title></title>
+ <style type="text/css">
+ .smallText {
+ font-size: xx-small;
+ }
+ .largeText {
+ font-size: xx-large;
+ }
+
+ .Selecteddayclass {
+ background-color: #0087FF;
+ }
+ </style>
</head>
<body>
<f:view>
+ <a4j:outputPanel ajaxRendered="true">
+ <h:messages />
+ </a4j:outputPanel>
<h:form>
<calendar:calendar
id="calendar"
+ data="#{calendarDataModel}"
locale="#{calendarBean.locale}"
popup="#{calendarBean.popup}"
- datePattern="#{calendarBean.pattern}">
+ datePattern="#{calendarBean.pattern}"
+ weekDayLabelsShort="#{calendarBean.weekDayLabelsShort}"
+ value="#{calendarBean.selectedDate}"
+ currentDate="#{calendarBean.currentDate}">
+
+ <f:validator validatorId="org.richfaces.CalendarValidator" />
+
+ <h:panelGrid columns="2">
+ <f:verbatim><p style="padding: 10px;"
class="largeText">{day}</p></f:verbatim>
+ <h:panelGrid>
+ <h:outputText styleClass="smallText" value="{data.enLabel}"
/>
+ <h:outputText styleClass="smallText" value="{data.frLabel}"
/>
+ <h:outputText styleClass="smallText" value="{data.deLabel}"
/>
+ </h:panelGrid>
+ </h:panelGrid>
</calendar:calendar>
<h:panelGrid columns="2">
<h:outputText value="Select Locale:" />
- <h:selectOneRadio onchange="submit()"
valueChangeListener="#{calendarBean.selectLocale}">
+ <h:selectOneRadio onchange="submit()" value="en/US"
valueChangeListener="#{calendarBean.selectLocale}">
<f:selectItem itemLabel="US" itemValue="en/US"/>
- <f:selectItem itemLabel="EN" itemValue="en/GB"/>
+ <f:selectItem itemLabel="DE" itemValue="de/DE"/>
<f:selectItem itemLabel="FR" itemValue="fr/FR"/>
+ <f:selectItem itemLabel="RU" itemValue="ru/RU"/>
</h:selectOneRadio>
<h:outputText value="Popup Mode:" />
- <h:selectBooleanCheckbox value="#{calendarBean.locale}"
onclick="submit()"/>
+ <h:selectBooleanCheckbox value="#{calendarBean.popup}"
onclick="submit()"/>
+ <h:outputText value="Custom day labels:" />
+ <h:selectBooleanCheckbox value="#{calendarBean.useCustomDayLabels}"
onclick="submit()"/>
<h:outputText value="Select Date Pattern:"/>
<h:selectOneMenu value="#{calendarBean.pattern}"
onchange="submit()">
<f:selectItem itemLabel="d/M/yy" itemValue="d/M/yy"/>
- <f:selectItem itemLabel="dd/MM/yy"
itemValue="dd/MM/yy"/>
+ <f:selectItem itemLabel="dd/M/yy" itemValue="dd/M/yy"/>
<f:selectItem itemLabel="d/MMM/y" itemValue="d/MMM/y"/>
- <f:selectItem itemLabel="MMM d, yyyy"
itemValue="d/MMM/y"/>
+ <f:selectItem itemLabel="MMM d, yyyy" itemValue="MMM d,
yyyy"/>
</h:selectOneMenu>
</h:panelGrid>
+ <h:outputText value="Current date: "/>
+ <h:outputText value="#{calendarBean.currentDateAsText}" />
+ <f:verbatim><br /></f:verbatim>
+ <h:outputText value="Selected date: "/>
+ <h:outputText value="#{calendarBean.selectedDate}" />
+ <f:verbatim><br /></f:verbatim>
+
+ <h:commandButton value="Submit"/>
+
</h:form>
</f:view>
</body>
Modified: trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml 2007-07-21 00:27:25
UTC (rev 1763)
+++ trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml 2007-07-21 00:37:29
UTC (rev 1764)
@@ -66,13 +66,13 @@
<name>preloadDateRangeBegin</name>
<classname>java.util.Date</classname>
<description></description>
- <defaultvalue>getDefaultPreloadBegin(getCurrentDate())</defaultvalue>
+ <defaultvalue>getDefaultPreloadBegin(getCurrentDateOrDefault())</defaultvalue>
</property>
<property elonly="true">
<name>preloadDateRangeEnd</name>
<classname>java.util.Date</classname>
<description></description>
- <defaultvalue>getDefaultPreloadEnd(getCurrentDate())</defaultvalue>
+ <defaultvalue>getDefaultPreloadEnd(getCurrentDateOrDefault())</defaultvalue>
</property>
<property elonly="true">
<name>currentDate</name>
@@ -98,5 +98,26 @@
<description></description>
<defaultvalue>true</defaultvalue>
</property>
+
+ <property>
+ <name>weekDayLabels</name>
+ <classname>java.lang.Object</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>weekDayLabelsShort</name>
+ <classname>java.lang.Object</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>monthLabels</name>
+ <classname>java.lang.Object</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>monthLabelsShort</name>
+ <classname>java.lang.Object</classname>
+ <description></description>
+ </property>
</component>
</components>
Copied:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java
(from rev 1734,
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CurrentDateChangeEvent.java)
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java
(rev 0)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/CurrentDateChangeEvent.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -0,0 +1,41 @@
+package org.richfaces.component;
+
+import java.util.Date;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+public class CurrentDateChangeEvent extends FacesEvent {
+
+ private Date currentDate = null;
+ private String currentDateString = null;
+
+ public CurrentDateChangeEvent(UIComponent component, Date curentDate) {
+ super(component);
+ this.currentDate = curentDate;
+
+ }
+ public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
+ super(component);
+ this.currentDateString = curentDateString;
+ }
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+ public void processListener(FacesListener listener) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
+
+ public Date getCurrentDate() {
+ return currentDate;
+ }
+
+ public String getCurrentDateString() {
+ return currentDateString;
+ }
+
+}
Modified: trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -53,7 +53,6 @@
import org.richfaces.model.CalendarDataModelItem;
import org.richfaces.renderkit.CalendarDataModelItemAdaptor;
import org.richfaces.renderkit.CalendarRendererBase;
-import org.richfaces.renderkit.CurrentDateChangeEvent;
// import org.richfaces.renderkit.html.BaseGradient.Data;
@@ -91,6 +90,21 @@
public abstract void setData(CalendarDataModel dataModel);
+ public abstract String getDatePattern();
+ public abstract void setDatePattern(String pattern);
+
+ public abstract Object getMonthLabels();
+ public abstract void setMonthLabels(Object labels);
+
+ public abstract Object getMonthLabelsShort();
+ public abstract void setMonthLabelsShort(Object labels);
+
+ public abstract Object getWeekDayLabels();
+ public abstract void setWeekDayLabels(Object labels);
+
+ public abstract Object getWeekDayLabelsShort();
+ public abstract void setWeekDayLabelsShort(Object labels);
+
// currentDate processing -------------------------------------------------
private Date currentDate = null;
@@ -101,6 +115,10 @@
Date valueString = calendar.getCurrentDate();
return valueString.toString();
}
+
+ public Calendar getCalendar() {
+ return Calendar.getInstance(getTimeZone(), getLocale());
+ }
public Date getConvertedValue(FacesContext context, String currentDateString)
throws ConverterException {
@@ -111,6 +129,12 @@
currentDateString);
return newCurrentDate;
}
+
+ protected void validateValue(FacesContext context, Object newValue) {
+ setSubmittedValue(newValue);
+ super.validateValue(context, newValue);
+ }
+
public void updateCurrentDate(FacesContext context, Date currentDate) {
if (context == null) {
@@ -143,6 +167,15 @@
return i;
}
+ public Date getCurrentDateOrDefault() {
+ Date date = getCurrentDate();
+ if (date != null) {
+ return date;
+ } else {
+ return getCalendar().getTime();
+ }
+ }
+
protected Date getDefaultPreloadBegin(Date date) {
Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
calendar.setTime(date);
Modified:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -22,8 +22,12 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -31,6 +35,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.DateTimeConverter;
import javax.faces.event.PhaseId;
import org.ajax4jsf.event.AjaxEvent;
@@ -40,7 +46,9 @@
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.util.SelectUtils;
+import org.richfaces.component.CurrentDateChangeEvent;
import org.richfaces.component.UICalendar;
+import org.richfaces.component.util.ComponentUtil;
import org.richfaces.component.util.HtmlUtil;
/**
@@ -49,6 +57,14 @@
*/
public class CalendarRendererBase extends TemplateEncoderRendererBase {
+ protected static final String MONTH_LABELS_SHORT = "monthLabelsShort";
+
+ protected static final String MONTH_LABELS = "monthLabels";
+
+ protected static final String WEEK_DAY_LABELS_SHORT = "weekDayLabelsShort";
+
+ protected static final String WEEK_DAY_LABELS = "weekDayLabels";
+
public static final String DATE_SCROLL = "DateScroll";
protected static final String MARKUP_SUFFIX = "Markup";
@@ -69,6 +85,21 @@
return HtmlUtil.qualifySize(size.toString());
}
+ public Object getConvertedValue(FacesContext context,
+ UIComponent component, Object submittedValue)
+ throws ConverterException {
+ if (submittedValue instanceof Date) {
+ return (Date) submittedValue;
+ }
+
+ DateTimeConverter converter = new DateTimeConverter();
+ UICalendar calendar = (UICalendar) component;
+ converter.setPattern(calendar.getDatePattern());
+ converter.setLocale(calendar.getLocale());
+ converter.setTimeZone(calendar.getTimeZone());
+ return converter.getAsObject(context, component, (String) submittedValue);
+ }
+
public Date convertCurrentDate(String currentDateString) {
Calendar calendar = Calendar.getInstance();
@@ -106,6 +137,10 @@
new AjaxEvent(component).queue();
}
+ String selectedDateString = (String) requestParameterMap.get(clientId +
"InputSelectedDate");
+ if (selectedDateString != null) {
+ ((UICalendar) component).setSubmittedValue(selectedDateString);
+ }
}
@@ -200,6 +235,109 @@
return value;
}
+ public void writeSymbols(FacesContext facesContext, UICalendar calendar) throws
IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ Map symbolsMap = getSymbolsMap(facesContext, calendar);
+ Iterator entryIterator = symbolsMap.entrySet().iterator();
+ while (entryIterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) entryIterator.next();
+
+ writer.writeText(entry.getKey(), null);
+ writer.writeText(": ", null);
+ writer.writeText(ScriptUtils.toScript(entry.getValue()), null);
+
+ if (entryIterator.hasNext()) {
+ writer.writeText(", ", null);
+ }
+ }
+ }
+
+ private static String[] shiftDates(int firstDayOfWeek, int minimum, int maximum,
String[] labels) {
+ if (minimum == 0) {
+ return labels;
+ }
+
+ String[] shiftedLabels = new String[maximum - minimum + 1];
+ System.arraycopy(labels, minimum, shiftedLabels, 0, maximum - minimum + 1);
+
+ return shiftedLabels;
+ }
+
+ protected Map getSymbolsMap(FacesContext facesContext, UICalendar calendar) {
+ Map map = new HashMap();
+
+ Locale locale = calendar.getLocale();
+ Calendar cal = calendar.getCalendar();
+ int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
+ int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);
+ int firstDayOfWeek = cal.getFirstDayOfWeek();
+
+ DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
+ String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels());
+ if (weekDayLabels == null) {
+ weekDayLabels = symbols.getWeekdays();
+ weekDayLabels = shiftDates(firstDayOfWeek, minimum, maximum, weekDayLabels);
+ }
+
+ String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort());
+ if (weekDayLabelsShort == null) {
+ weekDayLabelsShort = symbols.getShortWeekdays();
+ weekDayLabelsShort = shiftDates(firstDayOfWeek, minimum, maximum,
weekDayLabelsShort);
+ }
+
+ String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels());
+ if (monthLabels == null) {
+ monthLabels = symbols.getMonths();
+ }
+
+ String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort());
+ if (monthLabelsShort == null) {
+ monthLabelsShort = symbols.getShortMonths();
+ }
+
+ map.put(WEEK_DAY_LABELS, weekDayLabels);
+ map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
+ map.put(MONTH_LABELS, monthLabels);
+ map.put(MONTH_LABELS_SHORT, monthLabelsShort);
+
+ return map;
+ }
+
+ public String getFirstWeekDay(FacesContext context, UICalendar calendar) throws
IOException {
+ Calendar cal = calendar.getCalendar();
+ return String.valueOf(cal.getFirstDayOfWeek() -
cal.getActualMinimum(Calendar.DAY_OF_WEEK));
+ }
+
+ public String getMinDaysInFirstWeek(FacesContext context, UICalendar calendar) throws
IOException {
+ Calendar cal = calendar.getCalendar();
+ return String.valueOf(cal.getMinimalDaysInFirstWeek());
+ }
+
+ public String getCurrentDate(FacesContext context, UICalendar calendar) throws
IOException {
+ Date date = calendar.getCurrentDateOrDefault();
+ return ScriptUtils.toScript(formatDate(date));
+ }
+
+ public String getSelectedDate(FacesContext context, UICalendar calendar) throws
IOException {
+ Object submittedValue = calendar.getSubmittedValue();
+ Date date;
+
+ if (submittedValue instanceof String) {
+ Converter converter = SelectUtils.getConverterForProperty(context, calendar,
"value");
+ date = (Date) converter.getAsObject(context, calendar, (String) submittedValue);
+ } else if (submittedValue != null) {
+ date = (Date) submittedValue;
+ } else {
+ date = (Date) calendar.getValue();
+ }
+
+ if (date != null) {
+ return ScriptUtils.toScript(formatDate(date));
+ }
+
+ return ScriptUtils.toScript(null);
+ }
+
public static Object formatDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Deleted:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CurrentDateChangeEvent.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CurrentDateChangeEvent.java 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CurrentDateChangeEvent.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -1,41 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.util.Date;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-
-public class CurrentDateChangeEvent extends FacesEvent {
-
- private Date currentDate = null;
- private String currentDateString = null;
-
- public CurrentDateChangeEvent(UIComponent component, Date curentDate) {
- super(component);
- this.currentDate = curentDate;
-
- }
- public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
- super(component);
- this.currentDateString = curentDateString;
- }
-
- public boolean isAppropriateListener(FacesListener listener) {
- return false;
- }
-
- public void processListener(FacesListener listener) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- public Date getCurrentDate() {
- return currentDate;
- }
-
- public String getCurrentDateString() {
- return currentDateString;
- }
-
-}
Modified:
trunk/sandbox/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
trunk/sandbox/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-07-21
00:37:29 UTC (rev 1764)
@@ -197,7 +197,7 @@
var weekDayCounter = this.params.firstWeekDay;
for (var i=0;i<7;i++)
{
- var weekDayHtml = this.evaluateMarkup(this.params.weekDayMarkup, {weekDayLabel:
this.params.weekDayLabels[weekDayCounter], weekDayNumber:weekDayCounter,
componentId:this.getWeekDayComponentId(i)} );
+ var weekDayHtml = this.evaluateMarkup(this.params.weekDayMarkup, {weekDayLabel:
this.params.weekDayLabelsShort[weekDayCounter], weekDayNumber:weekDayCounter,
componentId:this.getWeekDayComponentId(i)} );
if (weekDayCounter==6) weekDayCounter=0; else weekDayCounter++;
styleClass = (i==this.firstWeekendDayNumber || i==this.secondWeekendDayNumber ?
"Weekendclass" : "calendar_days");
@@ -424,8 +424,8 @@
var todayflag = (currentYear == this.todayDate.getFullYear() && currentMonth ==
this.todayDate.getMonth());
var todaydate = this.todayDate.getDate();
- var selectedflag = (currentYear == this.selectedDate.getFullYear() &&
currentMonth == this.selectedDate.getMonth())
- var selecteddate = this.selectedDate.getDate();
+ var selectedflag = this.selectedDate && (currentYear ==
this.selectedDate.getFullYear() && currentMonth == this.selectedDate.getMonth())
+ var selecteddate = this.selectedDate && this.selectedDate.getDate();
var wd = getDay(this.currentDate, this.params.firstWeekDay);
var currentMonthDays = daysInMonthByDate(this.currentDate);
Modified: trunk/sandbox/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
---
trunk/sandbox/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-07-21
00:37:29 UTC (rev 1764)
@@ -25,13 +25,12 @@
dayListTableId: '#{clientId}Day',
weekNumberBarId: '#{clientId}WeekNum',
weekDayBarId: '#{clientId}WeekDay',
- currentDate: new Date(2007,6,1),
- selectedDate: new Date(2007,4,5),
- weekDayLabels:
['Sun','Mon','Tue','Wen','Thu','Fri','Sat'],
- monthLabels: ['January', 'February', 'March',
'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'],
- monthLabelsShort: ['Jan', 'Feb', 'Mar', 'Apr',
'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'],
- firstWeekDay: 0,
- minDaysInFirstWeek: 4,
+ currentDate: #{this:getCurrentDate(context, component)},
+ selectedDate: #{this:getSelectedDate(context, component)},
+ datePattern: '#{component.datePattern}',
+ <f:call name="writeSymbols" />,
+ firstWeekDay: #{this:getFirstWeekDay(context, component)},
+ minDaysInFirstWeek: #{this:getMinDaysInFirstWeek(context, component)},
headerOptionalMarkup: [new E('b',{},[new T('User defined
header')])],
footerOptionalMarkup: [new E('b',{},[new T('User defined
header')])],
<jsp:scriptlet>/*<![CDATA[*/
Modified:
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
---
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-21
00:27:25 UTC (rev 1763)
+++
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-21
00:37:29 UTC (rev 1764)
@@ -5,13 +5,10 @@
import java.util.Calendar;
import java.util.Date;
-import java.util.List;
import java.util.Locale;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlForm;
-import javax.faces.component.html.HtmlOutputText;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;