Author: amarkhel
Date: 2010-11-17 11:53:40 -0500 (Wed, 17 Nov 2010)
New Revision: 20079
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/model/
trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
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/resources/META-INF/resources/org.richfaces/calendar.js
Log:
RF-9683 Calendar component: data model support, RF-9684 Calendar component: AJAX
scrolling
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-11-17
16:48:10 UTC (rev 20078)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-11-17
16:53:40 UTC (rev 20079)
@@ -22,16 +22,24 @@
package org.richfaces.component;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.AbortProcessingException;
@@ -43,22 +51,28 @@
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.event.CurrentDateChangeEvent;
+import org.richfaces.event.CurrentDateChangeListener;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.CalendarDataModel;
+import org.richfaces.model.CalendarDataModelItem;
+import org.richfaces.renderkit.MetaComponentRenderer;
import org.richfaces.utils.CalendarHelper;
-import org.richfaces.event.CurrentDateChangeEvent;
-import org.richfaces.event.CurrentDateChangeListener;
-
/**
* @author amarkhel
*
*/
@JsfComponent(type = AbstractCalendar.COMPONENT_TYPE, family =
AbstractCalendar.COMPONENT_FAMILY, generate =
"org.richfaces.component.UICalendar", renderer = @JsfRenderer(type =
"org.richfaces.CalendarRenderer"), tag = @Tag(name = "calendar"))
-public abstract class AbstractCalendar extends UIInput {
+public abstract class AbstractCalendar extends UIInput implements MetaComponentResolver,
MetaComponentEncoder {
+ public static final String DAYSDATA_META_COMPONENT_ID = "daysData";
+
public static final String COMPONENT_TYPE = "org.richfaces.Calendar";
public static final String COMPONENT_FAMILY = "org.richfaces.Calendar";
@@ -75,7 +89,12 @@
locale
};
+ public enum Modes {
+ CLIENT,
+ AJAX
+ }
+
@Attribute(defaultValue = "MMM d, yyyy")
public abstract String getDatePattern();
@@ -144,6 +163,9 @@
@Attribute(defaultValue = "3")
public abstract int getZindex();
+
+ @Attribute(defaultValue = "client")
+ public abstract String getMode();
@Attribute
public abstract String getStyle();
@@ -184,6 +206,7 @@
@Attribute
public abstract Object getCurrentDate();
+ @Attribute
public abstract void setCurrentDate(Object date);
@Attribute
@@ -194,6 +217,19 @@
@Attribute
public abstract Object getDefaultTime();
+
+ @Attribute(defaultValue =
"getDefaultPreloadBegin(getCurrentDateOrDefault())")
+ public abstract Object getPreloadDateRangeBegin();
+
+ public abstract void setPreloadDateRangeBegin(Object date);
+
+ @Attribute(defaultValue =
"getDefaultPreloadEnd(getCurrentDateOrDefault())")
+ public abstract Object getPreloadDateRangeEnd();
+
+ public abstract void setPreloadDateRangeEnd(Object date);
+
+ @Attribute
+ public abstract CalendarDataModel getDataModel();
@Attribute(events = @EventName("inputclick"))
public abstract String getOninputclick();
@@ -306,7 +342,46 @@
public CurrentDateChangeListener[] getCurrentDateChangeListeners() {
return (CurrentDateChangeListener[])
getFacesListeners(CurrentDateChangeListener.class);
}
+
+ protected Date getDefaultPreloadBegin(Date date) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Calendar calendar = Calendar.getInstance(getTimeZone(),
+ CalendarHelper.getAsLocale(facesContext, this, getLocale()));
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
+ return calendar.getTime();
+ }
+ protected Date getDefaultPreloadEnd(Date date) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Calendar calendar = Calendar.getInstance(getTimeZone(),
+ CalendarHelper.getAsLocale(facesContext, this, getLocale()));
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
+ /*
+ * //force recalculation calendar.getTimeInMillis();
+ * calendar.set(Calendar.DAY_OF_WEEK, getLastDayOfWeek(calendar));
+ */
+ return calendar.getTime();
+ }
+
+ public Date getCurrentDateOrDefault() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ Date date = CalendarHelper.getAsDate(facesContext, this, getCurrentDate());
+
+ if (date != null) {
+ return date;
+ } else {
+ Date value = CalendarHelper.getAsDate(facesContext, this, this.getValue());
+ if (value != null) {
+ return value;
+ } else {
+ return java.util.Calendar.getInstance(getTimeZone()).getTime();
+ }
+ }
+ }
+
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof CurrentDateChangeEvent) {
FacesContext facesContext = getFacesContext();
@@ -348,4 +423,110 @@
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
}
}
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
+ if (DAYSDATA_META_COMPONENT_ID.equals(metaComponentId)) {
+ return getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+ return null;
+ }
+
+ public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent
contextComponent,
+ String metaComponentId) {
+ return null;
+ }
+
+ @Override
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
+ if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER)
{
+
+ VisitResult result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
+ DAYSDATA_META_COMPONENT_ID);
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ } else if (result == VisitResult.REJECT) {
+ return false;
+ }
+ }
+ }
+
+ return super.visitTree(context, callback);
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
+ }
+
+ public Object getPreload() {
+ Date[] preloadDateRange = getPreloadDateRange();
+ if (preloadDateRange != null && preloadDateRange.length != 0) {
+ CalendarDataModel calendarDataModel = (CalendarDataModel) getDataModel();
+ if (calendarDataModel != null) {
+ CalendarDataModelItem[] calendarDataModelItems = calendarDataModel
+ .getData(preloadDateRange);
+
+ HashMap<String, Object> args = new HashMap<String,
Object>();
+
+ args.put("startDate", formatStartDate(preloadDateRange[0]));
+ args.put("days", calendarDataModelItems);
+ return args;
+ }
+ }
+ return null;
+ }
+
+ public static Object formatStartDate(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ HashMap <String, Object> hashDate = new HashMap<String,Object>();
+ hashDate.put("month", calendar.get(Calendar.MONTH));
+ hashDate.put("year", calendar.get(Calendar.YEAR));
+ return hashDate;
+ }
+
+ public Date[] getPreloadDateRange() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ Date dateRangeBegin = null;
+ Date dateRangeEnd = null;
+
+ if (Modes.AJAX.toString().equalsIgnoreCase(getMode())) {
+ dateRangeBegin = CalendarHelper.getAsDate(facesContext, this,
+ getDefaultPreloadBegin((Date) getCurrentDate()));
+ dateRangeEnd = CalendarHelper.getAsDate(facesContext, this,
+ getDefaultPreloadEnd((Date) getCurrentDate()));
+ } else {
+ dateRangeBegin = CalendarHelper.getAsDate(facesContext, this,
getPreloadDateRangeBegin());
+ dateRangeEnd = CalendarHelper.getAsDate(facesContext, this,
getPreloadDateRangeEnd());
+ }
+
+ if (dateRangeBegin == null && dateRangeEnd == null) {
+ return null;
+ } else {
+ if (dateRangeBegin.after(dateRangeEnd)) {
+ // XXX add message
+ FacesMessage message = new FacesMessage(
+ "preloadDateRangeBegin is greater than
preloadDateRangeEnd");
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ facesContext.addMessage(getClientId(facesContext), message);
+ throw new IllegalArgumentException();
+ }
+
+ List<Date> dates = new ArrayList<Date>();
+
+ Calendar calendar = Calendar.getInstance(this.getTimeZone(),
CalendarHelper.getAsLocale(facesContext, this, this.getLocale()));
+ Calendar calendar2 = (Calendar) calendar.clone();
+ calendar.setTime(dateRangeBegin);
+ calendar2.setTime(dateRangeEnd);
+
+ do {
+ dates.add(calendar.getTime());
+ calendar.add(Calendar.DATE, 1);
+ } while (!calendar.after(calendar2));
+
+ return (Date[]) dates.toArray(new Date[dates.size()]);
+ }
+ }
}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
(rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-11-17
16:53:40 UTC (rev 20079)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.model;
+
+import java.util.Date;
+/**
+ * @author Alexej Kushunin
+ * created 19.06.2007
+ *
+ */
+public interface CalendarDataModel {
+ /**
+ * @return array of CalendarDataModelItems for selected dates.
+ * This method will be called every time when components will need next
+ * block of CalendarDataItems.
+ * That may happens when calendar rendered, or when user navigate to
+ * next(previous) month or in any other case when calendar renders.
+ * This method will be called in Ajax mode when Calendar renders new page.
+ * */
+ CalendarDataModelItem[] getData(Date[] dateArray);
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
(rev 0)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-11-17
16:53:40 UTC (rev 20079)
@@ -0,0 +1,47 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.model;
+
+
+
+/**
+ * @author Alexej Kushunin
+ * created 19.06.2007
+ *
+ */
+
+public interface CalendarDataModelItem {
+ /**
+ *@return true if date is �selectable� on calendar, default
+ *implementation return true
+ **/
+ boolean isEnabled();
+
+ /**
+ * @return String that will be appended to style class for that date span.
+ * For example it may be �relevant holyday� � that mean class will be like
�rich-cal-day relevant holyday�.
+ * Default implementation return empty string.
+ * */
+ public String getStyleClass();
+}
+
+
+
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-11-17
16:48:10 UTC (rev 20078)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-11-17
16:53:40 UTC (rev 20079)
@@ -40,14 +40,17 @@
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.DateTimeConverter;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.component.AbstractCalendar;
+import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.component.util.SelectUtils;
@@ -73,7 +76,7 @@
@ResourceDependency(library = "org.richfaces", name =
"calendar-utils.js"),
@ResourceDependency(library = "org.richfaces", name =
"calendar.js"),
@ResourceDependency(library = "org.richfaces", name =
"calendar.ecss") })
-public class CalendarRendererBase extends InputRendererBase {
+public class CalendarRendererBase extends InputRendererBase implements
MetaComponentRenderer {
public static final String CALENDAR_BUNDLE =
"org.richfaces.renderkit.calendar";
@@ -146,9 +149,8 @@
public static final String CALENDAR_DISABLE_ICON_RESOURCE_NAME =
"disabledCalendarIcon.png";
public static final String CURRENT_DATE_INPUT = "InputCurrentDate";
-
-
+ public static final String OPTION_MODE = "mode";
protected static final Map<String, ComponentAttribute>
CALENDAR_INPUT_HANDLER_ATTRIBUTES =
Collections.unmodifiableMap(ComponentAttribute.createMap(
@@ -200,7 +202,7 @@
private static final String MINUTES_VALUE = "minutes";
protected void doDecode(FacesContext context, UIComponent component) {
- if(!(component instanceof AbstractCalendar)) {
+ if (!(component instanceof AbstractCalendar)) {
return;
}
@@ -221,6 +223,15 @@
if (selectedDateString != null) {
calendar.setSubmittedValue(selectedDateString);
}
+
+ if (requestParameterMap.get(component.getClientId(context) + ".ajax")
!= null) {
+ PartialViewContext pvc = context.getPartialViewContext();
+ pvc.getRenderIds().add(
+ component.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ + AbstractCalendar.DAYSDATA_META_COMPONENT_ID);
+
+ context.renderResponse();
+ }
}
public void renderInputHandlers(FacesContext facesContext, UIComponent component)
throws IOException {
@@ -256,7 +267,7 @@
@Override
public String getInputValue(FacesContext facesContext, UIComponent component) {
- if(!(component instanceof AbstractCalendar)) {
+ if (!(component instanceof AbstractCalendar)) {
return null;
}
@@ -290,11 +301,11 @@
public String getButtonIcon(FacesContext facesContext, UIComponent component) {
boolean disable = (Boolean)component.getAttributes().get("disabled");
String buttonIcon =
(String)component.getAttributes().get("buttonIcon");
- if(disable) {
+ if (disable) {
buttonIcon =
(String)component.getAttributes().get("buttonIconDisabled");
}
- if(buttonIcon != null && buttonIcon.trim().length() != 0) {
+ if (buttonIcon != null && buttonIcon.trim().length() != 0) {
buttonIcon = ViewUtil.getResourceURL(buttonIcon, facesContext);
} else {
buttonIcon = disable ? CALENDAR_ICON_RESOURCE_NAME:
CALENDAR_ICON_RESOURCE_NAME;
@@ -307,11 +318,11 @@
public Object getSelectedDate(FacesContext facesContext, UIComponent component)
throws IOException {
Object returnValue = null;
AbstractCalendar calendar = (AbstractCalendar)component;
- if(calendar.isValid()) {
+ if (calendar.isValid()) {
Date date;
Object value = calendar.getValue();
date = CalendarHelper.getAsDate(facesContext, calendar, value);
- if(date != null) {
+ if (date != null) {
returnValue = formatSelectedDate(calendar.getTimeZone(), date);
}
}
@@ -382,7 +393,6 @@
return ((dayStyleClass != null && dayStyleClass.trim().length() != 0)) ?
new JSReference(dayStyleClass) : null;
}
-
public Map<String, Object> getLabels(FacesContext facesContext,
AbstractCalendar calendar) {
ResourceBundle bundle1 = null;
ResourceBundle bundle2 = null;
@@ -409,11 +419,11 @@
protected Map<String, Object> getCollectedLabels(ResourceBundle [] bundles ,
String[] names) {
Map<String, Object> labels = new HashMap<String, Object>();
- if(bundles != null && names != null) {
+ if (bundles != null && names != null) {
for (String name: names) {
String label = null;
String bundleKey = "RICH_CALENDAR_" + name.toUpperCase() +
"_LABEL";
- for(ResourceBundle bundle: bundles) {
+ for (ResourceBundle bundle: bundles) {
if (bundle != null) {
try {
label = bundle.getString(bundleKey);
@@ -421,7 +431,7 @@
// Current key was not found, ignore this exception;
}
}
- if(label != null) {
+ if (label != null) {
break;
}
}
@@ -478,36 +488,35 @@
int monthMin = calendar.getActualMinimum(Calendar.MONTH);
String [] weekDayLabels =
RenderKitUtils.asArray(calendarComponent.getWeekDayLabels());
- if(weekDayLabels == null) {
+ if (weekDayLabels == null) {
weekDayLabels = dateFormat.getWeekdays();
weekDayLabels = shiftDates(minimum, maximum, weekDayLabels);
}
RenderKitUtils.addToScriptHash(map, WEEK_DAY_LABELS, weekDayLabels);
String [] weekDayLabelsShort =
RenderKitUtils.asArray(calendarComponent.getWeekDayLabelsShort());
- if(weekDayLabelsShort == null) {
+ if (weekDayLabelsShort == null) {
weekDayLabelsShort = dateFormat.getShortWeekdays();
weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort);
}
RenderKitUtils.addToScriptHash(map, WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
String [] monthLabels =
RenderKitUtils.asArray(calendarComponent.getMonthLabels());
- if(monthLabels == null) {
+ if (monthLabels == null) {
monthLabels = dateFormat.getMonths();
monthLabels = shiftDates(monthMin, monthMax, monthLabels);
}
RenderKitUtils.addToScriptHash(map, MONTH_LABELS, monthLabels);
-
String [] monthLabelsShort =
RenderKitUtils.asArray(calendarComponent.getMonthLabelsShort());
- if(monthLabelsShort == null) {
+ if (monthLabelsShort == null) {
monthLabelsShort = dateFormat.getShortMonths();
monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort);
}
RenderKitUtils.addToScriptHash(map, MONTH_LABELS_SHORT, monthLabelsShort);
int minDaysInFirstWeek = calendarComponent.getMinDaysInFirstWeek();
- if(minDaysInFirstWeek == Integer.MIN_VALUE) {
+ if (minDaysInFirstWeek == Integer.MIN_VALUE) {
minDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
}
@@ -516,7 +525,7 @@
}
int day = calendarComponent.getFirstWeekDay();
- if(day == Integer.MIN_VALUE) {
+ if (day == Integer.MIN_VALUE) {
day = calendar.getFirstDayOfWeek();
day = calendar.getFirstDayOfWeek() -
calendar.getActualMinimum(Calendar.DAY_OF_WEEK);
}
@@ -526,7 +535,6 @@
} else if (day != Integer.MIN_VALUE) {
facesContext.getExternalContext().log(day + " value of firstWeekDay
attribute is not a legal one for component: " + MessageUtil.getLabel(facesContext,
calendarComponent) + ". Default value was applied.");
}
-
return map;
}
@@ -538,7 +546,7 @@
scriptOptions.addOption(OPTION_READONLY);
scriptOptions.addOption(OPTION_RESET_TIME_ON_DATE_SELECT);
scriptOptions.addOption(OPTION_SHOW_APPLY_BUTTON);
- scriptOptions.addOption(OPTION_POPUP);
+ scriptOptions.addOption(OPTION_POPUP);
scriptOptions.addOption(OPTION_SHOW_INPUT);
scriptOptions.addOption(OPTION_SHOW_HEADER);
scriptOptions.addOption(OPTION_SHOW_FOOTER);
@@ -565,12 +573,13 @@
scriptOptions.addOption("styleClass");
scriptOptions.addOption("style", HtmlUtil.concatStyles("z-index:
" + calendar.getZindex(), calendar.getStyle()));
+ scriptOptions.addOption(OPTION_MODE, calendar.getMode());
return scriptOptions;
}
public void buildAddLocaleScript(ResponseWriter writer, FacesContext facesContext,
UIComponent component) throws IOException {
- if(component instanceof AbstractCalendar) {
+ if (component instanceof AbstractCalendar) {
AbstractCalendar calendar = (AbstractCalendar)component;
JSFunction function = new
JSFunction("RichFaces.ui.Calendar.addLocale",
CalendarHelper.getAsLocale(facesContext, calendar).toString(),
getLocaleOptions(facesContext, calendar));
writer.write(function.toScript());
@@ -579,12 +588,18 @@
}
public void buildCalendarScript(ResponseWriter writer, FacesContext facesContext,
UIComponent component) throws IOException {
- if(component instanceof AbstractCalendar) {
+ if (component instanceof AbstractCalendar) {
AbstractCalendar calendar = (AbstractCalendar)component;
ScriptOptions scriptOptions = createCalendarScriptOption(facesContext,
calendar);
JSFunction function = new JSFunction("new RichFaces.ui.Calendar",
calendar.getClientId(facesContext), CalendarHelper.getAsLocale(facesContext,
calendar).toString(), scriptOptions, "");
StringBuffer scriptBuffer = new StringBuffer();
- scriptBuffer.append(function.toScript()).append(".load();");
+ scriptBuffer.append(function.toScript()).append(".load(");
+ Object preload = calendar.getPreload();
+ if (null != preload){
+ scriptBuffer.append(RenderKitUtils.toScriptArgs(preload));
+ }
+
+ scriptBuffer.append(");");
writer.write(scriptBuffer.toString());
}
}
@@ -599,11 +614,11 @@
}
protected Converter setupConverter(FacesContext facesContext, Converter converter,
AbstractCalendar calendar) {
- if(converter == null || calendar == null) {
+ if (converter == null || calendar == null) {
return null;
}
- if(converter instanceof DateTimeConverter) {
+ if (converter instanceof DateTimeConverter) {
DateTimeConverter defaultConverter = (DateTimeConverter) converter;
defaultConverter.setPattern(calendar.getDatePattern());
defaultConverter.setLocale( CalendarHelper.getAsLocale(facesContext,
calendar));
@@ -611,5 +626,21 @@
}
return converter;
}
+
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
+ if (AbstractCalendar.DAYSDATA_META_COMPONENT_ID.equals(metaComponentId)) {
+ Object preload = ((AbstractCalendar) component).getPreload();
+ if (preload != null) {
+ Map<String, Object> dataMap =
AjaxContext.getCurrentInstance(context).getResponseComponentDataMap();
+ dataMap.put(component.getClientId(context), preload);
+ }
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+ }
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
+ throw new UnsupportedOperationException();
+ }
}
\ No newline at end of file
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-11-17
16:48:10 UTC (rev 20078)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-11-17
16:53:40 UTC (rev 20079)
@@ -261,6 +261,7 @@
selectedDate: null,
currentDate: null,
defaultTime: {hours:12,minutes:0, seconds:0},
+ mode: "client",
hidePopupOnScroll: true
};
@@ -494,6 +495,9 @@
this.scrollElements = null;
//alert(new Date().getTime()-_d.getTime());
+
+ //define isAjaxMode variable
+ "ajax" == this.params.mode ? this.isAjaxMode = true : this.isAjaxMode =
false;
};
@@ -1118,10 +1122,12 @@
}
},
- indexData:function(daysData, isAjaxMode) {
- var dateYear = daysData.startDate.getFullYear();
- var dateMonth = daysData.startDate.getMonth();
+ indexData: function(daysData, isAjaxMode) {
+ var dateYear = daysData.startDate.year;
+ var dateMonth = daysData.startDate.month;
+ daysData.startDate = new Date(dateYear,dateMonth)
+
daysData.index = [];
daysData.index[dateYear+'-'+dateMonth] = 0;
if (isAjaxMode)
@@ -1402,12 +1408,31 @@
var formattedDate =
rf.calendarUtils.formatDate(this.getCurrentDate(),"MM/yyyy");
rf.getDomElement(this.id+'InputCurrentDate').value=formattedDate;
- if (this.submitFunction)
- this.submitFunction.call(this, formattedDate);
+ if (this.isAjaxMode && this.callAjax)
+ this.callAjax.call(this, formattedDate);
else
this.render();
},
+ callAjax: function(calendar, date) {
+ var _this = this;
+ var ajaxSuccess = function (event) {
+ if (event.componentData && event.componentData[_this.id])
+ {
+ var dataDays=event.componentData[_this.id]
+ _this.load(dataDays, true);
+ }
+ }
+ var ajaxError = function (event) {
+ // do nothing
+ }
+ var params = {};
+ params[this.id + ".ajax"] = "1";
+
+ rf.ajax(this.id, null, {parameters: params, error: ajaxError, complete:ajaxSuccess});
+
+ },
+
nextMonth: function() {
this.changeCurrentDateOffset(0,1);
},